The decrypt function works on the first pass throu...
# cfml-general
h
The decrypt function works on the first pass through of the looped query, without fail. Everything after that is a flop. I generate a new key on every pass thru and encrypt and decrypt with the same key. This is driving me bonkers. Am I doing something incorrectly here, or is this an issue with Lucee?
p
You should never want just a decrypt-able password. Always use bcrypt one way.
đź’Ż 4
h
Thanks. Not helpful however. Appreciate the response however.
p
Well just trying to be helpful so you do not create a vulnerable environment for your app.
d
Share your code and error message. It’s not clear what the issue.
h
I'll check that out, thanks @Patrick
No error is generated. I'll copy the output from the screen and post
That is Hugh's code; obviously just manually set a
pw
it all appears to work.
d
@hugh delete that shared code from the channel and post it here in this thread. please.
h
Copy code
query datasource="XXXXXXX" name="q" sql="

select username, pw from user

";

loop query="q"{

	key = generateSecretKey('AES');

	echo("Encrypted with ::>[ #key# ] - ")

	enc = encrypt(pw, key, 'AES')

	echo(enc & "<br><br>")

	dec = decrypt(enc, key, 'AES')

	echo("Decrypted with ::>[ #key# ] - #dec#<hr>")

}
d
@hugh I meant to say delete the output from the chaannel
@hugh this code share is good. I don't need the output.
h
@Daniel Mejia Done
There it is with a simple loop over passwords too; appears working
h
@Patrick Ok interesting. Then there must be something up with my system
p
are you potentially looping over an already encrypted password in the DB?
d
yes inspect the passwords. should work.
h
@Patrick OMG Patrick, you're absolutely correct on that. There was already hashed PW's in the table. Such a dummy. Sorry to bother you all
👍🏾 1
p
No problem; but seriously consider stronger encryption methods like Bcrypt.
g
Not trying to harp on, Sometimes you need a user pass that is reversible… so will leave that choice up to you. Just wanted to share that one of the things I like about bcrypt - the passwords start with $2a then $16 for the work factor… so you can decide when/if you update the encryption over time. As hardware improves you can use change regenerate passwords with low work orders… when they login, if they are old just create and store a stronger one.
Although you can’t reverse them you have information that it is bcrypt, and the work factor used… unless someone just uses that in their password lmao
It’s a great way to slowly roll out passwords as people login, if it starts that way use bcrypt otherwise use the old system and save the password as bcrypt from then on. Means you can migrate with the same password field