Commit 2cc4c23b authored by Quxl's avatar Quxl

修改密码加密规则

parent 5ef770df
...@@ -18,6 +18,7 @@ import com.egolm.film.api.member.service.MemberService; ...@@ -18,6 +18,7 @@ import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member; import com.egolm.film.bean.Fc_member;
import com.egolm.film.common.EmailService; import com.egolm.film.common.EmailService;
import com.egolm.film.common.Messages; import com.egolm.film.common.Messages;
import com.egolm.film.config.Common;
import com.egolm.film.config.interceptor.LocaleSessionInterceptor; import com.egolm.film.config.interceptor.LocaleSessionInterceptor;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -49,9 +50,12 @@ public class MemberOpenApiController { ...@@ -49,9 +50,12 @@ public class MemberOpenApiController {
}) })
public Object register(HttpServletRequest request, String username, String password, String email) { public Object register(HttpServletRequest request, String username, String password, String email) {
Locale locale = LocaleContextHolder.getLocale(); Locale locale = LocaleContextHolder.getLocale();
String salt = Common.getGenerateString(6);
String encodePwd = memberService.encodePassword(salt, password);
Fc_member member = new Fc_member(); Fc_member member = new Fc_member();
member.setSalt(salt);
member.setUsername(username); member.setUsername(username);
member.setPassword(memberService.encodePassword(password)); member.setPassword(encodePwd);
member.setEmail(email); member.setEmail(email);
member.setCreate_ip(ServletUtil.remoteIp(request)); member.setCreate_ip(ServletUtil.remoteIp(request));
member.setCreate_time(System.currentTimeMillis()); member.setCreate_time(System.currentTimeMillis());
......
...@@ -7,7 +7,7 @@ import com.egolm.film.bean.Fc_member; ...@@ -7,7 +7,7 @@ import com.egolm.film.bean.Fc_member;
public interface MemberService { public interface MemberService {
String encodePassword(String password); String encodePassword(String salt, String password);
Fc_member getMemberByEmail(String email); Fc_member getMemberByEmail(String email);
......
...@@ -21,7 +21,7 @@ public class MemberServiceImpl implements MemberService { ...@@ -21,7 +21,7 @@ public class MemberServiceImpl implements MemberService {
@Override @Override
public void changePassword(String id, String newPassword) { public void changePassword(String id, String newPassword) {
String sql = "update fc_member set password = ? where id = ?"; String sql = "update fc_member set password = ? where id = ?";
jdbcTemplate.executeUpdate(sql, this.encodePassword(newPassword), id); jdbcTemplate.executeUpdate(sql, newPassword, id);
} }
@Override @Override
...@@ -31,8 +31,8 @@ public class MemberServiceImpl implements MemberService { ...@@ -31,8 +31,8 @@ public class MemberServiceImpl implements MemberService {
} }
@Override @Override
public String encodePassword(String password) { public String encodePassword(String salt, String password) {
return StringUtil.toMD5HexString(password); return StringUtil.toMD5HexString(StringUtil.toMD5HexString(password + salt).toLowerCase().substring(4, 20)).toLowerCase();
} }
@Override @Override
......
package com.egolm.film.config;
import java.util.Random;
public class Common {
public static final String SOURCES="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
public static String getGenerateString(int length) {
Random random = new Random();
char[] text = new char[length];
for (int i = 0; i < length; i++) {
text[i] = SOURCES.charAt(random.nextInt(SOURCES.length()));
}
return new String(text);
}
public static void main(String[] args) {
System.out.println(getGenerateString(8));
}
}
...@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service; ...@@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil; import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate; import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.common.Messages; import com.egolm.film.common.Messages;
import com.egolm.film.config.WebMvcConfig; import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException; import com.egolm.film.config.XException;
...@@ -25,21 +26,30 @@ public class MemberTokenServiceImpl implements MemberTokenService { ...@@ -25,21 +26,30 @@ public class MemberTokenServiceImpl implements MemberTokenService {
@Autowired @Autowired
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Autowired
private MemberService memberService;
@Override @Override
public LoginToken doLogin(String username, String password) { public LoginToken doLogin(String username, String password) {
HttpSession session = WebMvcConfig.getSession(); HttpSession session = WebMvcConfig.getSession();
String md5String = StringUtil.toMD5HexString(password).toLowerCase(); String loginSql = "select * from fc_member where email = ?";
String loginSql = "select * from fc_member where email = ? and password = ?"; List<Map<String, Object>> list = this.jdbcTemplate.queryForList(loginSql, username);
List<Map<String, Object>> list = this.jdbcTemplate.queryForList(loginSql, username, md5String);
if(list != null) { if(list != null) {
if(list.size() == 1) { if(list.size() == 1) {
Map<String,Object> map = list.get(0); Map<String,Object> map = list.get(0);
Integer state = (Integer)map.get("state"); Integer state = (Integer)map.get("state");
if(state == 1) { if(state == 1) {
Integer id = (Integer)map.get("id"); String salt = (String)map.get("salt");
LoginToken token = new LoginToken(id); String dbPwd = (String)map.get("password");
session.setAttribute(TOKEN_NAME, token); String encodePassword = memberService.encodePassword(salt, password);
return token; if(encodePassword.equals(dbPwd)) {
Integer id = (Integer)map.get("id");
LoginToken token = new LoginToken(id);
session.setAttribute(TOKEN_NAME, token);
return token;
} else {
throw new XException(messages.get("sys.err.user_pwd_err"));
}
} else if(state == 2) { } else if(state == 2) {
throw new XException(messages.get("sys.err.user_disabled")); throw new XException(messages.get("sys.err.user_disabled"));
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment