I am working on Spring Security application and I am using BCryptPasswordEncoder for encoding the passwords in the db. I used the following generator
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
public class PasswordEncoderGenerator {
public static void main(String[] args) {
int i = 0;
while (i < 10) {
String password = "1234";
BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
String hashedPassword = passwordEncoder.encode(password);
System.out.println(hashedPassword);
i++;
}
}
}
I am storing the credentials in postgres data base. I updated my table manually pasting the output from this short program because there were only several users. What I want to achieve is creating update query that allows me to encrypt the password using sql query.
I installed
postgresql-contrib libpq-dev
module and now I am trying to execute the following query:
UPDATE users
SET login_pin = crypt('0000', gen_salt('bf'))
WHERE user_id = '1';
I was not able to find bcrypt in the official postgres documentation and I put 'bf' in the gen_salt() function. http://www.postgresql.org/docs/8.3/static/pgcrypto.html
Then I checked my db and it inserted 60 char long string with some symbols but it seems that 0000 pin is wrong. I need to use bcrypt instead of bf. Anybody can help?
Thanks