LoginServiceImpl.java
932 Bytes
package com.xkl.service;
import com.xkl.domain.User;
import com.xkl.repository.UserRepository;
import com.xkl.security.SecurityTool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* Created by win7 on 2016/12/18.
*/
@Service
public class LoginServiceImpl implements ILoginService{
@Autowired
private UserRepository userRepository;
@Override
public User check(String username, String password) {
User user = userRepository.findByLoginAccount(username);
if (user == null) { //用户不存在
return null;
} else {
String salt = user.getSalt();
String pass_in_db = user.getLoginPwd();
String pass = SecurityTool.getPassword(username, password, salt);
if (!pass.equals(pass_in_db))//密码错误
return null;
}
return user;
}
}