Why BCryptPasswordEncoder from Spring generate different outputs for same input?

前端 未结 4 2070
你的背包
你的背包 2020-12-13 19:03

I am using BCryptPasswordEncoder with Spring security. My expectation was that for the same input I will always get the same output. But for the same input I get different o

4条回答
  •  萌比男神i
    2020-12-13 19:49

    That is perfectly normal because BCryptPasswordEncoder uses a salt to generate the password. You can read about the idea behind "salting" a password here and here.

    This is what the documentation says for the encode method

    Encode the raw password. Generally, a good encoding algorithm applies a SHA-1 or greater hash combined with an 8-byte or greater randomly generated salt.

提交回复
热议问题