use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncAddEmailTest method shouldNotAddMailIfAlreadyUsed.
@Test
public void shouldNotAddMailIfAlreadyUsed() {
// given
String email = "player@mail.tld";
given(player.getName()).willReturn("TestName");
given(playerCache.isAuthenticated("testname")).willReturn(true);
PlayerAuth auth = mock(PlayerAuth.class);
given(auth.getEmail()).willReturn(null);
given(playerCache.getAuth("testname")).willReturn(auth);
given(validationService.validateEmail(email)).willReturn(true);
given(validationService.isEmailFreeForRegistration(email, player)).willReturn(false);
// when
asyncAddEmail.addEmail(player, email);
// then
verify(service).send(player, MessageKey.EMAIL_ALREADY_USED_ERROR);
verify(playerCache, never()).updatePlayer(any(PlayerAuth.class));
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class RakamakConverter method execute.
@Override
public // TODO ljacqu 20151229: Restructure this into smaller portions
void execute(CommandSender sender) {
boolean useIp = settings.getProperty(ConverterSettings.RAKAMAK_USE_IP);
String fileName = settings.getProperty(ConverterSettings.RAKAMAK_FILE_NAME);
String ipFileName = settings.getProperty(ConverterSettings.RAKAMAK_IP_FILE_NAME);
File source = new File(pluginFolder, fileName);
File ipFiles = new File(pluginFolder, ipFileName);
Map<String, String> playerIp = new HashMap<>();
Map<String, HashedPassword> playerPassword = new HashMap<>();
try {
BufferedReader ipFile = new BufferedReader(new FileReader(ipFiles));
String line;
if (useIp) {
String tempLine;
while ((tempLine = ipFile.readLine()) != null) {
if (tempLine.contains("=")) {
String[] args = tempLine.split("=");
playerIp.put(args[0], args[1]);
}
}
}
ipFile.close();
BufferedReader users = new BufferedReader(new FileReader(source));
while ((line = users.readLine()) != null) {
if (line.contains("=")) {
String[] arguments = line.split("=");
HashedPassword hashedPassword = passwordSecurity.computeHash(arguments[1], arguments[0]);
playerPassword.put(arguments[0], hashedPassword);
}
}
users.close();
for (Entry<String, HashedPassword> m : playerPassword.entrySet()) {
String playerName = m.getKey();
HashedPassword psw = playerPassword.get(playerName);
String ip = useIp ? playerIp.get(playerName) : "127.0.0.1";
PlayerAuth auth = PlayerAuth.builder().name(playerName).realName(playerName).ip(ip).password(psw).lastLogin(0).build();
database.saveAuth(auth);
}
Utils.logAndSendMessage(sender, "Rakamak database has been imported correctly");
} catch (IOException ex) {
ConsoleLogger.logException("Can't open the rakamak database file! Does it exist?", ex);
}
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class VAuthConverter method execute.
@Override
public void execute(CommandSender sender) {
try (Scanner scanner = new Scanner(vAuthPasswordsFile)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
String name = line.split(": ")[0];
String password = line.split(": ")[1];
PlayerAuth auth;
if (isUuidInstance(password)) {
String pname;
try {
pname = Bukkit.getOfflinePlayer(UUID.fromString(name)).getName();
} catch (Exception | NoSuchMethodError e) {
pname = getName(UUID.fromString(name));
}
if (pname == null) {
continue;
}
auth = PlayerAuth.builder().name(pname.toLowerCase()).realName(pname).password(password, null).build();
} else {
auth = PlayerAuth.builder().name(name.toLowerCase()).realName(name).password(password, null).build();
}
dataSource.saveAuth(auth);
}
} catch (IOException e) {
ConsoleLogger.logException("Error while trying to import some vAuth data", e);
}
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class XAuthConverter method convert.
private void convert(CommandSender sender) {
if (pluginManager.getPlugin("xAuth") == null) {
sender.sendMessage("[AuthMe] xAuth plugin not found");
return;
}
// TODO ljacqu 20160702: xAuthDb is not used except for the existence check -- is this intended?
File xAuthDb = new File(dataFolder.getParent(), makePath("xAuth", "xAuth.h2.db"));
if (!xAuthDb.exists()) {
sender.sendMessage("[AuthMe] xAuth H2 database not found, checking for MySQL or SQLite data...");
}
List<Integer> players = getXAuthPlayers();
if (Utils.isCollectionEmpty(players)) {
sender.sendMessage("[AuthMe] Error while importing xAuthPlayers: did not find any players");
return;
}
sender.sendMessage("[AuthMe] Starting import...");
for (int id : players) {
String pl = getIdPlayer(id);
String psw = getPassword(id);
if (psw != null && !psw.isEmpty() && pl != null) {
PlayerAuth auth = PlayerAuth.builder().name(pl.toLowerCase()).realName(pl).password(psw, null).build();
database.saveAuth(auth);
}
}
sender.sendMessage("[AuthMe] Successfully converted from xAuth database");
}
use of fr.xephi.authme.data.auth.PlayerAuth in project AuthMeReloaded by AuthMe.
the class AsyncChangePassword method changePassword.
public void changePassword(final Player player, String oldPassword, String newPassword) {
final String name = player.getName().toLowerCase();
PlayerAuth auth = playerCache.getAuth(name);
if (passwordSecurity.comparePassword(oldPassword, auth.getPassword(), player.getName())) {
HashedPassword hashedPassword = passwordSecurity.computeHash(newPassword, name);
auth.setPassword(hashedPassword);
if (!dataSource.updatePassword(auth)) {
commonService.send(player, MessageKey.ERROR);
return;
}
playerCache.updatePlayer(auth);
commonService.send(player, MessageKey.PASSWORD_CHANGED_SUCCESS);
ConsoleLogger.info(player.getName() + " changed his password");
} else {
commonService.send(player, MessageKey.WRONG_PASSWORD);
}
}
Aggregations