use of games.strategy.engine.lobby.server.db.HashedPassword in project triplea by triplea-game.
the class ModeratorControllerIntegrationTest method setUp.
@BeforeEach
public void setUp() throws UnknownHostException {
moderatorController = new ModeratorController(serverMessenger, null);
final String adminName = Util.createUniqueTimeStamp();
final DBUser dbUser = new DBUser(new DBUser.UserName(adminName), new DBUser.UserEmail("n@n.n"), DBUser.Role.ADMIN);
final UserController userController = new UserController();
userController.createUser(dbUser, new HashedPassword(BCrypt.hashpw(adminName, BCrypt.gensalt())));
userController.makeAdmin(dbUser);
adminNode = new Node(adminName, InetAddress.getLocalHost(), 0);
when(serverMessenger.getPlayerMac(adminName)).thenReturn(newHashedMacAddress());
}
use of games.strategy.engine.lobby.server.db.HashedPassword in project triplea by triplea-game.
the class LobbyLoginValidator method createUser.
@Nullable
private String createUser(final Map<String, String> response, final User user) {
final DBUser dbUser = new DBUser(new DBUser.UserName(user.getUsername()), new DBUser.UserEmail(response.get(EMAIL_KEY)));
if (!dbUser.isValid()) {
return dbUser.getValidationErrorMessage();
}
if (userDao.doesUserExist(dbUser.getName())) {
return "That user name has already been taken";
}
final HashedPassword password = new HashedPassword(response.get(HASHED_PASSWORD_KEY));
if (RsaAuthenticator.canProcessResponse(response)) {
return rsaAuthenticator.decryptPasswordForAction(response, pass -> {
final HashedPassword newPass = new HashedPassword(BCrypt.hashpw(pass, bcryptSaltGenerator.newSalt()));
if (password.isHashedWithSalt()) {
userDao.createUser(dbUser, password);
userDao.updateUser(dbUser, newPass);
} else {
userDao.createUser(dbUser, newPass);
}
return null;
});
}
if (!password.isHashedWithSalt()) {
return "Password is not hashed correctly";
}
try {
userDao.createUser(dbUser, password);
return null;
} catch (final Exception e) {
return e.getMessage();
}
}
use of games.strategy.engine.lobby.server.db.HashedPassword in project triplea by triplea-game.
the class LobbyLoginValidator method authenticateRegisteredUser.
@Nullable
private String authenticateRegisteredUser(final Map<String, String> response, final User user) {
final String username = user.getUsername();
final String errorMessage = ErrorMessages.AUTHENTICATION_FAILED;
final HashedPassword hashedPassword = userDao.getPassword(username);
if (hashedPassword == null) {
return errorMessage;
}
if (RsaAuthenticator.canProcessResponse(response)) {
return rsaAuthenticator.decryptPasswordForAction(response, pass -> {
final String legacyHashedPassword = response.get(HASHED_PASSWORD_KEY);
if (hashedPassword.isBcrypted()) {
if (userDao.login(username, new HashedPassword(pass))) {
if (legacyHashedPassword != null && userDao.getLegacyPassword(username).value.isEmpty()) {
userDao.updateUser(userDao.getUserByName(username), new HashedPassword(legacyHashedPassword));
userDao.updateUser(userDao.getUserByName(username), new HashedPassword(BCrypt.hashpw(pass, bcryptSaltGenerator.newSalt())));
}
return null;
}
return errorMessage;
} else if (userDao.login(username, new HashedPassword(legacyHashedPassword))) {
userDao.updateUser(userDao.getUserByName(username), new HashedPassword(BCrypt.hashpw(pass, bcryptSaltGenerator.newSalt())));
return null;
} else {
return errorMessage;
}
});
}
if (!userDao.login(username, new HashedPassword(response.get(HASHED_PASSWORD_KEY)))) {
return errorMessage;
}
return null;
}
Aggregations