For now, using the feature: rails g authentication
in rails 8
if we create two users with the same one password, then password_digest
is same too.
I suppose should add salt(which generate random by bcrypt) to make password more scure.
I think we can learn from here
Have you included the bcrypt gem? It should be generating a salt each time and storing that in the field. See this StackOverflow answer for how that works.
yes, bcrypt
already salt the password by default.
At the beginning, I habitually think that there must br a independent field of salt
in table of user. later I found that both password hash and password salt already saved in just one field which is password_digest
.
and I found the entire process is:
- find the user by email_address
- extract the salt by the
user.password_digest.salt
- calculate digest of the salt and params[:password]
- compare the digest and password_digest in db
Any way, thank you so much on this