private void setV0Password (User u, String clearpass) throws Exception { assertNotNull(clearpass, "Invalid password"); u.setPasswordHash(HashVersion.ZERO.hash(Long.toString(u.getId()), clearpass, null)); } }
public boolean upgradePassword (User u, String clearpass) throws Exception { assertNotNull(clearpass, "Invalid pass"); String passwordHash = u.getPasswordHash(); assertNotNull(passwordHash, "Password is null"); HashVersion v = HashVersion.getVersion(passwordHash); if (v == HashVersion.ZERO && checkV0Password(passwordHash, u.getId(), clearpass)) { setPassword(u, clearpass, null, HashVersion.ONE); return true; } return false; }
/** * @param nick name. * @param pass hash * @return the user * @throws BLException if invalid user/pass * @throws HibernateException on low level hibernate related exception */ public User getUserByNick (String nick, String pass) throws Exception { User u = getUserByNick(nick); assertNotNull (u, "User does not exist"); assertTrue(checkPassword(u, pass), "Invalid password"); return u; }
private void setV1Password (User u, String clearpass) throws Exception { assertNotNull(clearpass, "Invalid password"); u.setPasswordHash(HashVersion.ONE.hash(Long.toString(u.getId(),16), clearpass, HashVersion.ONE.getSalt())); }
public boolean checkPassword (User u, String clearpass) throws Exception { assertNotNull(clearpass, "Invalid pass"); String passwordHash = u.getPasswordHash(); assertNotNull(passwordHash, "Password is null"); HashVersion v = HashVersion.getVersion(passwordHash); assertTrue(v != HashVersion.UNKNOWN, "Unknown password"); switch (v) { case ZERO: return checkV0Password(passwordHash, u.getId(), clearpass); case ONE: return checkV1Password(passwordHash, clearpass); } return false; }