/** * Generate a salt for use with the BCrypt.hashpw() method, * selecting a reasonable default for the number of hashing * rounds to apply * @return an encoded salt value */ public static String gensalt() { return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS); }
/** * Generate a salt for use with the BCrypt.hashpw() method * @param log_rounds the log2 of the number of rounds of * hashing to apply - the work factor therefore increases as * 2**log_rounds. * @return an encoded salt value */ public static String gensalt(int log_rounds) { return gensalt(log_rounds, new SecureRandom()); }
@Override public byte[] generateSalt() { return BCrypt.gensalt(workFactor).getBytes(StandardCharsets.UTF_8); }
public String encodePassword(String rawPass, Object obj) throws DataAccessException { return BCrypt.hashpw(rawPass,BCrypt.gensalt()); }
@Override public String hash(String password) { return hash(password, BCrypt.gensalt(this.saltSize)); }
@Override public byte[] hash( byte[] input, CredentialsInfo info, UUID userId, UUID applicationId ) { return BCrypt.hashpw(new String(input, UTF8), BCrypt.gensalt(defaultIterations)).getBytes(); }
@Override public void storeHashPassword(UserDto user, String password) { requireNonNull(password, "Password cannot be null"); user.setHashMethod(HashMethod.BCRYPT.name()) .setCryptedPassword(BCrypt.hashpw(password, BCrypt.gensalt(12))) .setSalt(null); } }
/** * Test method for 'BCrypt.gensalt()' */ public void testGensalt() { System.out.print("BCrypt.gensalt(): "); for (int i = 0; i < test_vectors.length; i += 4) { String plain = test_vectors[i][0]; String salt = BCrypt.gensalt(); String hashed1 = BCrypt.hashpw(plain, salt); String hashed2 = BCrypt.hashpw(plain, hashed1); assertEquals(hashed1, hashed2); System.out.print("."); } System.out.println(""); }
/** * Test method for 'BCrypt.gensalt(int)' */ public void testGensaltInt() { System.out.print("BCrypt.gensalt(log_rounds):"); for (int i = 4; i <= 12; i++) { System.out.print(" " + Integer.toString(i) + ":"); for (int j = 0; j < test_vectors.length; j += 4) { String plain = test_vectors[j][0]; String salt = BCrypt.gensalt(i); String hashed1 = BCrypt.hashpw(plain, salt); String hashed2 = BCrypt.hashpw(plain, hashed1); assertEquals(hashed1, hashed2); System.out.print("."); } } System.out.println(""); }
/** * Test for correct hashing of non-US-ASCII passwords */ public void testInternationalChars() { System.out.print("BCrypt.hashpw w/ international chars: "); String pw1 = "\u2605\u2605\u2605\u2605\u2605\u2605\u2605\u2605"; String pw2 = "????????"; String h1 = BCrypt.hashpw(pw1, BCrypt.gensalt()); assertFalse(BCrypt.checkpw(pw2, h1)); System.out.print("."); String h2 = BCrypt.hashpw(pw2, BCrypt.gensalt()); assertFalse(BCrypt.checkpw(pw1, h2)); System.out.print("."); System.out.println(""); }
@Test public void authentication_with_bcrypt_with_correct_password_should_work() { String password = randomAlphanumeric(60); UserDto user = newUserDto() .setHashMethod(BCRYPT.name()) .setCryptedPassword(BCrypt.hashpw(password, BCrypt.gensalt(12))); underTest.authenticate(db.getSession(), user, password, AuthenticationEvent.Method.BASIC); }
@Test public void authentication_with_bcrypt_with_incorrect_password_should_throw_AuthenticationException() { String password = randomAlphanumeric(60); UserDto user = newUserDto() .setHashMethod(BCRYPT.name()) .setCryptedPassword(BCrypt.hashpw(password, BCrypt.gensalt(12))); expectedException.expect(AuthenticationException.class); expectedException.expectMessage("wrong password"); underTest.authenticate(db.getSession(), user, "WHATEVER", AuthenticationEvent.Method.BASIC); }
password.setTextContent(BCrypt.hashpw(apikey, BCrypt.gensalt(4))); changed = true;
/** * Creates or updates a user. */ public default GraphTraversal<S, Vertex> user(final String username, final String password) { return has(VERTEX_LABEL_USER, PROPERTY_USERNAME, username). fold(). coalesce(__.unfold(), __.addV(VERTEX_LABEL_USER).property(PROPERTY_USERNAME, username)). property(PROPERTY_PASSWORD, BCrypt.hashpw(password, BCrypt.gensalt(CredentialTraversalDsl.BCRYPT_ROUNDS))); } }
/** * Generate a salt for use with the BCrypt.hashpw() method, * selecting a reasonable default for the number of hashing * rounds to apply * @return an encoded salt value */ public static String gensalt() { return gensalt(GENSALT_DEFAULT_LOG2_ROUNDS); }
/** * Creates or updates a user. */ public GraphTraversal<Vertex, Vertex> user(final String username, final String password) { return this.clone().V(). has(VERTEX_LABEL_USER, PROPERTY_USERNAME, username). fold(). coalesce(__.unfold(), __.addV(VERTEX_LABEL_USER).property(PROPERTY_USERNAME, username)). property(PROPERTY_PASSWORD, BCrypt.hashpw(password, BCrypt.gensalt(CredentialTraversalDsl.BCRYPT_ROUNDS))); } }
/** * Generate a salt for use with the BCrypt.hashpw() method * @param log_rounds the log2 of the number of rounds of * hashing to apply - the work factor therefore increases as * 2**log_rounds. * @return an encoded salt value */ public static String gensalt(int log_rounds) { return gensalt(log_rounds, new SecureRandom()); }
/** * Generate crypted hash of give password * @param password the password * @return the password hash */ public String passwordHash(String password) { if (null == password) { return null; } return BCrypt.hashpw(password, BCrypt.gensalt()); }
/** * bcrypt hash function implemented by Spring Security. * * @param s the string to be hashed * @return the hash */ public static String bcrypt(String s) { return (s == null) ? s : BCrypt.hashpw(s, BCrypt.gensalt(12)); }
public static String getBCrypt(String text) { // gensalt's log_rounds parameter determines the complexity // the work factor is 2^log_rounds, and the default is 10 return BCrypt.hashpw(text, BCrypt.gensalt(12)); }