Commit 8d0cfc7f authored by Quxl's avatar Quxl

优化

parent 04e05577
......@@ -52,7 +52,7 @@ public class MemberOpenApiController {
public Object register(HttpServletRequest request, String username, String password, String email) {
Locale locale = LocaleContextHolder.getLocale();
String salt = Common.getGenerateString(6);
String encodePwd = memberService.encodePassword(salt, password);
String encodePwd = Common.encodePassword(password, salt);
Fc_member member = new Fc_member();
member.setSalt(salt);
member.setUsername(username);
......@@ -74,7 +74,7 @@ public class MemberOpenApiController {
int code = (int) ((Math.random() * 9 + 1) * 10000000);
String password = String.valueOf(code);
Fc_member member = memberService.getMemberByEmail(email);
String encodePwd = memberService.encodePassword(member.getSalt(), password);
String encodePwd = Common.encodePassword(password, member.getSalt());
memberService.changePassword(member.getId(), encodePwd);
String name = member.getUsername();
String subject = messages.get("email.getPassword.subject");
......
......@@ -7,8 +7,6 @@ import com.egolm.film.bean.Fc_member;
public interface MemberService {
String encodePassword(String salt, String password);
Fc_member getMemberByEmail(String email);
void changePassword(Integer id, String newPassword);
......
......@@ -6,7 +6,6 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.egolm.common.StringUtil;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member;
......@@ -30,11 +29,6 @@ public class MemberServiceImpl implements MemberService {
return jdbcTemplate.queryForBean(sql, Fc_member.class, email);
}
@Override
public String encodePassword(String salt, String password) {
return StringUtil.toMD5HexString(StringUtil.toMD5HexString(password + salt).toLowerCase().substring(4, 24)).toLowerCase();
}
@Override
public void saveMember(Fc_member member) {
jdbcTemplate.save(member);
......
......@@ -2,6 +2,8 @@ package com.egolm.film.config;
import java.util.Random;
import com.egolm.common.StringUtil;
public class Common {
public static final String SOURCES="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
......@@ -19,4 +21,7 @@ public class Common {
System.out.println(getGenerateString(8));
}
public static String encodePassword(String password, String salt) {
return StringUtil.toMD5HexString(StringUtil.toMD5HexString(password + salt).toLowerCase().substring(4, 24)).toLowerCase();
}
}
......@@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
import com.egolm.film.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member;
import com.egolm.film.common.Messages;
import com.egolm.film.config.Common;
import com.egolm.film.config.WebMvcConfig;
import com.egolm.film.config.XException;
import com.egolm.film.login.service.MemberTokenService;
......@@ -30,7 +31,7 @@ public class MemberTokenServiceImpl implements MemberTokenService {
if(state == 1) {
String salt = member.getSalt();
String dbPwd = member.getPassword();
String encodePassword = memberService.encodePassword(salt, password);
String encodePassword = Common.encodePassword(password, salt);
if(encodePassword.equals(dbPwd)) {
Integer id = member.getId();
LoginToken token = new LoginToken(id);
......
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