2

I have plain text password in char[]. How can I hash this char[] using org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder and store in database. What database datatype to use to store the hashed password (mySQL).

I want to avoid using Strings because this.

Community
  • 1
  • 1
Hanamiya
  • 43
  • 3
  • 1
    Even if this fear is not overblown, this may be impractical to implement all the way through the stack. Where do you get the user input from? If it's based on a Servlet API, your data has most likely already been turned into a String. – Thilo Sep 11 '16 at 10:14

1 Answers1

2

You can use a CharBuffer:

bcrypt.encode(CharBuffer.wrap(myPasswordArray));

As for storing it in the database, the method returns a String (which should be of if not fixed at least reasonably small length), so this can be stored in a regular varchar column.

Thilo
  • 257,207
  • 101
  • 511
  • 656