com.eshore.uas.system.DefaultUserAuth Maven / Gradle / Ivy
package com.eshore.uas.system;
import com.eshore.uas.extensions.Glue;
import com.eshore.uas.extensions.Password;
import com.eshore.uas.server.api.User;
import com.eshore.uas.server.api.UserAuth;
import com.eshore.uas.server.api.UserProvider;
public class DefaultUserAuth implements UserAuth {
private UserProvider userProvider;
public DefaultUserAuth(UserProvider up) {
userProvider=up;
}
@Override
public User auth(String account, String pwd) {
Password p = Glue.getPassword();
User u = userProvider.findByAccount(account);
if(u==null)return null;
String hp =u.getPasswd();
String salt =u.getSalt();
if(salt==null)salt="";
String whp =p.encode(pwd, salt);
if(whp.equals(hp))return u;
return null;
}
@Override
public User auth(String account, String pwd, String domain) {
return auth(account,pwd);
}
@Override
public boolean authCode(String code, String ticket) {
return true;
}
}