Search in sources :

Example 6 with DBUser

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))));
}
Also used : DBUser(games.strategy.engine.lobby.server.userDB.DBUser) Test(org.junit.jupiter.api.Test)

Example 7 with DBUser

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;
}
Also used : DBUser(games.strategy.engine.lobby.server.userDB.DBUser)

Example 8 with DBUser

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();
}
Also used : DBUser(games.strategy.engine.lobby.server.userDB.DBUser) DBUser(games.strategy.engine.lobby.server.userDB.DBUser) UserController(games.strategy.engine.lobby.server.db.UserController)

Example 9 with DBUser

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();
    }
}
Also used : DBUser(games.strategy.engine.lobby.server.userDB.DBUser) HashedPassword(games.strategy.engine.lobby.server.db.HashedPassword) Nullable(javax.annotation.Nullable)

Aggregations

DBUser (games.strategy.engine.lobby.server.userDB.DBUser)9 HashedPassword (games.strategy.engine.lobby.server.db.HashedPassword)3 UserController (games.strategy.engine.lobby.server.db.UserController)3 Test (org.junit.jupiter.api.Test)3 INode (games.strategy.net.INode)2 CreateUpdateAccountPanel (games.strategy.engine.lobby.client.login.CreateUpdateAccountPanel)1 IUserManager (games.strategy.engine.lobby.server.IUserManager)1 Node (games.strategy.net.Node)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Nullable (javax.annotation.Nullable)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1