LoginServiceImpl.java
2 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.xkl.service;
import com.xkl.config.Constants;
import com.xkl.domain.User;
import com.xkl.domain.XklAdminEntity;
import com.xkl.repository.AdminRepository;
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;
@Autowired
private AdminRepository adminRepository;
@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;
}
@Override
public XklAdminEntity checkAdmin(String username, String password) {
XklAdminEntity admin = adminRepository.findByAccountAndStatus(username, Constants.STATUS_OK);
if(admin == null){
return null;
}else{
String salt = admin.getSalt();
String adminType = Integer.toString(admin.getType());
String str = admin.getAccount() + password + adminType + salt; // 构建待加密字符串
String calcuPass = SecurityTool.encode(SecurityTool.ALGORITHM_MD5, str);
String pass_in_db = admin.getPwd();
if (!calcuPass.equals(pass_in_db))//密码错误
return null;
}
return admin;
}
}