mydb=> select * From test_user where username ='user3'and password=crypt('123456',password); id | username | password ----+----------+------------------------------------ 5| user3 | $1$cS7Bs67A$5c2FTClGTOBYiHpG1HyvA/ (1 row)
mydb=> select * From test_user where username ='user4'and password=crypt('123456',password); id | username | password ----+----------+------------------------------------ 6| user4 | $1$L6Rao5/l$7URcaCbT9Hrsrt9JcoBGq. (1 row)
附: 函数解释
crypt() crypt(password text, salt text) returns text Calculates a crypt(3)-style hash of password. When storing a new password, you need to use gen_salt() to generate a new salt value. To check a password, pass the stored hash value as salt, and test whether the result matches the stored value.
crypt() 函数支持的加密算法
gen_salt() gen_salt(type text [, iter_count integer ]) returns text Generates a new random salt string for use in crypt(). The salt string also tells crypt() which algorithm to use. The type parameter specifies the hashing algorithm. The accepted types are: des, xdes, md5 and bf.