DEV Community

Discussion on: How to Securely Store a Password in Java

Collapse
 
pojntfx profile image
Felicitas Pojtinger
// Java
import java.security.SecureRandom;

private static final SecureRandom RAND = new SecureRandom();

System.out.println(RAND)
Enter fullscreen mode Exit fullscreen mode

Just in case someone ever asks me why I refuse to use Java ;)

// JavaScript/TypeScript
import { hash } from 'bcrypt'

const random: string = hash('seed', 10)

console.log(random)
Enter fullscreen mode Exit fullscreen mode

Very nice article though!

Collapse
 
billoneil profile image
Bill O'Neil

You can use BCrypt in Java as well Hashing passwords in Java with BCrypt.

public String hash(String password) {
    return BCrypt.hashpw(password, BCrypt.gensalt(logRounds));
}

public boolean verifyHash(String password, String hash) {
    return BCrypt.checkpw(password, hash);
}
Enter fullscreen mode Exit fullscreen mode