LoginServiceImpl.java
1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.xkl.service;
import com.xkl.config.Constants;
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.findByLoginAccountAndStatus(username, Constants.STATUS_OK2);
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;
}
@Override
public User check(String username) {
User user = userRepository.findByLoginAccountAndStatus(username.trim(), Constants.STATUS_OK2);
return user;
}
}