use of games.strategy.engine.lobby.server.userDB.DBUser in project triplea by triplea-game.
the class UserControllerIntegrationTest method testLogin.
@Test
public void testLogin() {
final String password = md5Crypt(Util.createUniqueTimeStamp());
final DBUser user = createUserWithHash(password, Function.identity());
controller.updateUser(user, new HashedPassword(bcrypt(obfuscate(password))));
assertTrue(controller.login(user.getName(), new HashedPassword(password)));
assertTrue(controller.login(user.getName(), new HashedPassword(obfuscate(password))));
}
use of games.strategy.engine.lobby.server.userDB.DBUser in project triplea by triplea-game.
the class UserControllerIntegrationTest method createUserWithHash.
private DBUser createUserWithHash(@Nullable final String password, final Function<String, String> hashingMethod) {
final String name = UUID.randomUUID().toString().substring(0, 20);
final DBUser user = new DBUser(new DBUser.UserName(name), new DBUser.UserEmail(name + "@none.none"));
controller.createUser(user, new HashedPassword(hashingMethod.apply(password)));
return user;
}
use of games.strategy.engine.lobby.server.userDB.DBUser in project triplea by triplea-game.
the class ModeratorController method isPlayerAdmin.
@Override
public boolean isPlayerAdmin(final INode node) {
final User user = getUserForNode(node);
final DBUser dbUser = new UserController().getUserByName(user.getUsername());
return dbUser != null && dbUser.isAdmin();
}
use of games.strategy.engine.lobby.server.userDB.DBUser 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();
}
}
Aggregations