/** 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(""); }
public static void main(String[] args) { final Scanner scanner = new Scanner(System.in); System.out.println("Enter password to encrypt: "); final String password = scanner.nextLine(); System.out.println(); System.out.format("Encrypted Password: {%s}", BCrypt.hashpw(password, BCrypt.gensalt())); System.out.println(); }
@Test public void testBCryptRandom() { for (int rounds = 0; rounds < 1000; rounds++) { String text = RandomStringUtil.randomAlphaNumeric(10); String hash = BCrypt.hashpw(text, BCrypt.gensalt(4)); assertTrue(BCrypt.checkpw(text, hash)); } }
/** 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.checkpw(String, String)' expecting success */ public void testCheckpw_success() { System.out.print("BCrypt.checkpw w/ good passwords: "); for (int i = 0; i < test_vectors.length; i++) { String plain = test_vectors[i][0]; String expected = test_vectors[i][2]; assertTrue(BCrypt.checkpw(plain, expected)); System.out.print("."); } System.out.println(""); }
public void addUser( String username, String password, String nickName, String job, String email, int points, String phonenumber) throws SQLException { String encryptPassword = BCrypt.hashpw(password, BCrypt.gensalt()); sqlBase.executeQueryPrepared( "INSERT INTO Profile (UserName, HashedPassword, NickName, Job, Email, Points, PhoneNumber) VALUES (?, ?, ?, ?, ?, ?, ?)", username, encryptPassword, nickName, job, email, new Integer(points).toString(), phonenumber); }
public void register(String email, String password, String username) throws SQLException { Statement stmnt = conn.createStatement(); java.util.Date d = new java.util.Date(); Timestamp ts = new Timestamp(d.getTime()); String created_at = ts.toString(); String updated_at = created_at; String sql = "INSERT INTO members (email,encrypted_password,username,created_at,updated_at) VALUES('" + email + "','" + BCrypt.hashpw(password, BCrypt.gensalt()) + "','" + username + "','" + created_at + "','" + updated_at + "')"; stmnt.execute(sql); }
/** Test method for 'BCrypt.checkpw(String, String)' expecting failure */ public void testCheckpw_failure() { System.out.print("BCrypt.checkpw w/ bad passwords: "); for (int i = 0; i < test_vectors.length; i++) { int broken_index = (i + 4) % test_vectors.length; String plain = test_vectors[i][0]; String expected = test_vectors[broken_index][2]; assertFalse(BCrypt.checkpw(plain, expected)); System.out.print("."); } System.out.println(""); }
/** Test method for 'BCrypt.hashpw(String, String)' */ public void testHashpw() { System.out.print("BCrypt.hashpw(): "); for (int i = 0; i < test_vectors.length; i++) { String plain = test_vectors[i][0]; String salt = test_vectors[i][1]; String expected = test_vectors[i][2]; String hashed = BCrypt.hashpw(plain, salt); assertEquals(hashed, expected); 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(""); }
public boolean attemptLogin(String email, String password) throws SQLException, IOException { String db_password = null; int memberId = -1; String strSQL = "Select id,encrypted_password From members where email='" + email + "' LIMIT 1"; Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery(strSQL); while (rs.next()) { memberId = rs.getInt(1); db_password = rs.getString(2); System.out.println(db_password); } stmt.close(); if (db_password == null || password == null) { return false; } if (BCrypt.checkpw(password, db_password)) { System.out.println("yes?"); return true; } return false; }
@Override public void run() { SOCKET_PORT = String.valueOf(socket.getRemoteSocketAddress()); dLog.trace("Starting to run server"); // get all users try { users = userSvc.getAllUsers(); } catch (Exception e2) { dLog.error("Unable to get all users", e2); } dLog.trace("Got " + users.size() + " users"); try { while (!exit) { out = new ObjectOutputStream(socket.getOutputStream()); in = new ObjectInputStream(socket.getInputStream()); dLog.trace("Successfully got input/output streams"); String inputStr = ""; out.writeObject("Burrito POS Server Connected. Enter Username: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"INPUT | " + inputStr); parent.updateStatus(appendInfo("INPUT | " + inputStr)); while (!inputStr.equals("exit") && !this.exit) { dLog.trace("Exit? " + exit); if (tUser.getUserName() == null) { tUser.setUserName(inputStr); out.writeObject("OK User " + inputStr + ", enter password: "******"OUTPUT | OK User " + inputStr + ", enter password: "******"OUTPUT | Burrito POS Server Connected. Enter Username: "******"Username: "******" | Password: "******"Stored user: "******" | stored pass: "******"OK User verified. Enter command: "); dLog.trace("OUTPUT | OK User verified. Enter command: "); parent.updateStatus(appendInfo("OUTPUT | OK User verified. Enter command: ")); auth = true; } else { tUser.setUserName(null); tUser.setPassword(null); out.writeObject("ERROR Invalid Credentials. Enter Username: "******"OUTPUT | ERROR Invalid Credentials. Enter Username: "******"OUTPUT | ERROR Invalid Credentials. Enter Username: "******"exit")) { out.writeObject("OK Command " + inputStr + " entered. Enter command: "); dLog.trace("OUTPUT | OK Command " + inputStr + " entered. Enter command: "); parent.updateStatus( appendInfo("OUTPUT | OK Command " + inputStr + " entered. Enter command: ")); } } inputStr = (String) in.readObject(); dLog.trace("INPUT | " + inputStr); parent.updateStatus(appendInfo("INPUT | " + inputStr)); } exit = true; try { dLog.trace("Closing the socket"); auth = false; out.writeObject("Exiting"); dLog.trace("Exiting"); parent.updateStatus(appendInfo("Exiting")); this.close(); } catch (Exception e1) { dLog.error("Exception in closing socket", e1); } } } catch (Exception e) { dLog.error("Exception in SocketManager run", e); } }
@Test public void testBCrypt() { String hash = BCrypt.hashpw("password", BCrypt.gensalt(7)); assertTrue(BCrypt.checkpw("password", hash)); }
public boolean verifyPassword(String username, String password) throws SQLException { return BCrypt.checkpw(password, getHashedPassword(username)); }
@Test public void testBCrypt() { String pw = "password"; String hash = BCrypt.hashpw(pw, BCrypt.gensalt(4)); Assert.assertTrue(BCrypt.checkpw(pw, hash)); }
@Override protected boolean passwordsMatch(String plainText, String hashed) { return BCrypt.checkpw(plainText, hashed); }