0

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

skywalker
  • 696
  • 2
  • 16
  • 37
  • How does it seem that it's wrong? And I'd suggest using a bit newer documentation (there are links in the top of the page) unless you're really using version 8.3 – Sami Kuhmonen Jul 29 '15 at 15:17
  • possible duplicate of [How can I hash passwords in postgresql?](http://stackoverflow.com/questions/2647158/how-can-i-hash-passwords-in-postgresql) – Sami Kuhmonen Jul 29 '15 at 15:17

0 Answers0