Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support xauth #1

Open
kikote300 opened this issue Apr 1, 2014 · 3 comments
Open

Support xauth #1

kikote300 opened this issue Apr 1, 2014 · 3 comments

Comments

@kikote300
Copy link

Support xauth code

@Shevchik
Copy link
Member

Shevchik commented Apr 3, 2014

Started working on it, altrough no guarantees that it will work on future xAuth versions because xAuth doesn't have a stable API.

@kikote300
Copy link
Author

Supported hash algorithms: xAuth,

@kikote300
Copy link
Author

package fr.xephi.authme.security.crypts;

import java.security.NoSuchAlgorithmException;

public class XAUTH implements EncryptionMethod {

@Override
public String getHash(String password, String salt)
        throws NoSuchAlgorithmException {
    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 hash, String password,
        String playerName) throws NoSuchAlgorithmException {
    int saltPos = (password.length() >= hash.length() ? hash.length() - 1 : password.length());
    String salt = hash.substring(saltPos, saltPos + 12);
    return hash.equals(getHash(password, salt));
}

public 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);
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants