ljacqu 731d085ccd #1128 Rename to camel case (PR #235)
* rename classes according to cammel case and make code reflect these updates

* rename according to cammel case

* rename to camel case more accuratley

* rename to camel case try 3; fix Ipb4 java doc

* retry rename camel case

* rename to camel case
2017-03-17 18:49:30 +01:00

42 lines
1.4 KiB
Java

package fr.xephi.authme.security.crypts;
import fr.xephi.authme.security.crypts.description.Recommendation;
import fr.xephi.authme.security.crypts.description.Usage;
@Recommendation(Usage.RECOMMENDED)
public class XAuth extends HexSaltedMethod {
private static String getWhirlpool(String message) {
Whirlpool w = new Whirlpool();
byte[] digest = new byte[Whirlpool.DIGESTBYTES];
w.NESSIEinit();
w.NESSIEadd(message);
w.NESSIEfinalize(digest);
return Whirlpool.display(digest);
}
@Override
public String computeHash(String password, String salt, String name) {
String hash = getWhirlpool(salt + password).toLowerCase();
int saltPos = password.length() >= hash.length() ? hash.length() - 1 : password.length();
return hash.substring(0, saltPos) + salt + hash.substring(saltPos);
}
@Override
public boolean comparePassword(String password, HashedPassword hashedPassword, String playerName) {
String hash = hashedPassword.getHash();
int saltPos = password.length() >= hash.length() ? hash.length() - 1 : password.length();
if (saltPos + 12 > hash.length()) {
return false;
}
String salt = hash.substring(saltPos, saltPos + 12);
return hash.equals(computeHash(password, salt, null));
}
@Override
public int getSaltLength() {
return 12;
}
}