use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class ChangePasswordAdminCommandTest method shouldReportWhenSaveFailed.
@Test
public void shouldReportWhenSaveFailed() {
// given
CommandSender sender = mock(CommandSender.class);
String player = "my_user12";
String password = "passPass";
given(playerCache.isAuthenticated(player)).willReturn(true);
given(validationService.validatePassword(password, player)).willReturn(new ValidationResult());
HashedPassword hashedPassword = mock(HashedPassword.class);
given(passwordSecurity.computeHash(password, player)).willReturn(hashedPassword);
given(dataSource.updatePassword(player, hashedPassword)).willReturn(false);
// when
command.executeCommand(sender, Arrays.asList(player, password));
runOptionallyAsyncTask(bukkitService);
// then
verify(validationService).validatePassword(password, player);
verify(service).send(sender, MessageKey.ERROR);
verify(passwordSecurity).computeHash(password, player);
verify(dataSource).updatePassword(player, hashedPassword);
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class NewAPI method registerPlayer.
/**
* Register an OFFLINE/ONLINE player with the given password.
*
* @param playerName The player to register
* @param password The password to register the player with
*
* @return true if the player was registered successfully
*/
public boolean registerPlayer(String playerName, String password) {
String name = playerName.toLowerCase();
HashedPassword result = passwordSecurity.computeHash(password, name);
if (isRegistered(name)) {
return false;
}
PlayerAuth auth = PlayerAuth.builder().name(name).password(result).realName(playerName).build();
return dataSource.saveAuth(auth);
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class EmailRegisterExecutorProviderTest method shouldCreatePlayerAuth.
@Test
public void shouldCreatePlayerAuth() {
// given
given(commonService.getProperty(EmailSettings.RECOVERY_PASSWORD_LENGTH)).willReturn(12);
given(passwordSecurity.computeHash(anyString(), anyString())).willAnswer(invocation -> new HashedPassword(invocation.getArgument(0)));
Player player = mock(Player.class);
TestHelper.mockPlayerIp(player, "123.45.67.89");
given(player.getName()).willReturn("Veronica");
World world = mock(World.class);
given(world.getName()).willReturn("someWorld");
given(player.getLocation()).willReturn(new Location(world, 48, 96, 144));
EmailRegisterParams params = EmailRegisterParams.of(player, "test@example.com");
// when
PlayerAuth auth = executor.buildPlayerAuth(params);
// then
assertThat(auth, hasAuthBasicData("veronica", "Veronica", "test@example.com", "123.45.67.89"));
assertThat(auth, hasAuthLocation(48, 96, 144, "someWorld", 0, 0));
assertThat(auth.getPassword().getHash(), stringWithLength(12));
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class PlayerAuth method deserialize.
/**
* Method to deserialize PlayerAuth
*
* @param str String
*/
public void deserialize(String str) {
String[] args = str.split(";");
this.nickname = args[0];
this.realName = args[1];
this.ip = args[2];
this.email = args[3];
this.password = new HashedPassword(args[4], args[5]);
this.groupId = Integer.parseInt(args[6]);
this.lastLogin = Long.parseLong(args[7]);
this.world = args[8];
this.x = Double.parseDouble(args[9]);
this.y = Double.parseDouble(args[10]);
this.z = Double.parseDouble(args[11]);
}
use of fr.xephi.authme.security.crypts.HashedPassword in project AuthMeReloaded by AuthMe.
the class PlayerAuthViewer method displayAuthToSender.
/**
* Outputs the PlayerAuth information to the given sender.
*
* @param auth the PlayerAuth to display
* @param sender the sender to send the messages to
*/
private void displayAuthToSender(PlayerAuth auth, CommandSender sender) {
sender.sendMessage(ChatColor.BLUE + "[AuthMe] Player " + auth.getNickname() + " / " + auth.getRealName());
sender.sendMessage("Email: " + auth.getEmail() + ". IP: " + auth.getLastIp() + ". Group: " + auth.getGroupId());
sender.sendMessage("Quit location: " + formatLocation(auth.getQuitLocX(), auth.getQuitLocY(), auth.getQuitLocZ(), auth.getWorld()));
sender.sendMessage("Last login: " + formatDate(auth.getLastLogin()));
sender.sendMessage("Registration: " + formatDate(auth.getRegistrationDate()) + " with IP " + auth.getRegistrationIp());
HashedPassword hashedPass = auth.getPassword();
sender.sendMessage("Hash / salt (partial): '" + safeSubstring(hashedPass.getHash(), 6) + "' / '" + safeSubstring(hashedPass.getSalt(), 4) + "'");
sender.sendMessage("TOTP code (partial): '" + safeSubstring(auth.getTotpKey(), 3) + "'");
}
Aggregations