Commit 4a832442 authored by Quxl's avatar Quxl

优化登陆校验,密码加密

parent 2cc4c23b
...@@ -71,11 +71,12 @@ public class MemberOpenApiController { ...@@ -71,11 +71,12 @@ public class MemberOpenApiController {
@ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email")}) @ApiImplicitParams({@ApiImplicitParam(paramType = "query", dataType = "string", required = true, name = "email")})
public Object getPassword(String email) { public Object getPassword(String email) {
int code = (int) ((Math.random() * 9 + 1) * 10000000); int code = (int) ((Math.random() * 9 + 1) * 10000000);
String newPassword = String.valueOf(code); String password = String.valueOf(code);
Fc_member member = memberService.getMemberByEmail(email); Fc_member member = memberService.getMemberByEmail(email);
memberService.changePassword(member.getAddress(), newPassword); String encodePwd = memberService.encodePassword(member.getSalt(), password);
memberService.changePassword(member.getId(), encodePwd);
String subject = messages.get("email.getPassword.subject"); String subject = messages.get("email.getPassword.subject");
String content = messages.get("email.getPassword.subject", member.getRealname(), newPassword); String content = messages.get("email.getPassword.subject", member.getRealname(), password);
emailService.send(subject, content, email); emailService.send(subject, content, email);
return Rjx.jsonOk(); return Rjx.jsonOk();
} }
......
...@@ -11,7 +11,7 @@ public interface MemberService { ...@@ -11,7 +11,7 @@ public interface MemberService {
Fc_member getMemberByEmail(String email); Fc_member getMemberByEmail(String email);
void changePassword(String id, String newPassword); void changePassword(Integer id, String newPassword);
void saveMember(Fc_member member); void saveMember(Fc_member member);
......
...@@ -19,7 +19,7 @@ public class MemberServiceImpl implements MemberService { ...@@ -19,7 +19,7 @@ public class MemberServiceImpl implements MemberService {
private JdbcTemplate jdbcTemplate; private JdbcTemplate jdbcTemplate;
@Override @Override
public void changePassword(String id, String newPassword) { public void changePassword(Integer id, String newPassword) {
String sql = "update fc_member set password = ? where id = ?"; String sql = "update fc_member set password = ? where id = ?";
jdbcTemplate.executeUpdate(sql, newPassword, id); jdbcTemplate.executeUpdate(sql, newPassword, id);
} }
......
package com.egolm.film.login.service.impl; package com.egolm.film.login.service.impl;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; 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.api.member.service.MemberService;
import com.egolm.film.bean.Fc_member;
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;
...@@ -23,27 +19,20 @@ public class MemberTokenServiceImpl implements MemberTokenService { ...@@ -23,27 +19,20 @@ public class MemberTokenServiceImpl implements MemberTokenService {
@Autowired @Autowired
private Messages messages; private Messages messages;
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired @Autowired
private MemberService memberService; private MemberService memberService;
@Override @Override
public LoginToken doLogin(String username, String password) { public LoginToken doLogin(String email, String password) {
HttpSession session = WebMvcConfig.getSession(); HttpSession session = WebMvcConfig.getSession();
String loginSql = "select * from fc_member where email = ?"; Fc_member member = memberService.getMemberByEmail(email);
List<Map<String, Object>> list = this.jdbcTemplate.queryForList(loginSql, username); Integer state = member.getState();
if(list != null) {
if(list.size() == 1) {
Map<String,Object> map = list.get(0);
Integer state = (Integer)map.get("state");
if(state == 1) { if(state == 1) {
String salt = (String)map.get("salt"); String salt = member.getSalt();
String dbPwd = (String)map.get("password"); String dbPwd = member.getPassword();
String encodePassword = memberService.encodePassword(salt, password); String encodePassword = memberService.encodePassword(salt, password);
if(encodePassword.equals(dbPwd)) { if(encodePassword.equals(dbPwd)) {
Integer id = (Integer)map.get("id"); Integer id = member.getId();
LoginToken token = new LoginToken(id); LoginToken token = new LoginToken(id);
session.setAttribute(TOKEN_NAME, token); session.setAttribute(TOKEN_NAME, token);
return token; return token;
...@@ -55,14 +44,6 @@ public class MemberTokenServiceImpl implements MemberTokenService { ...@@ -55,14 +44,6 @@ public class MemberTokenServiceImpl implements MemberTokenService {
} else { } else {
throw new XException(messages.get("sys.err")); throw new XException(messages.get("sys.err"));
} }
} else if(list.size() == 0) {
throw new XException(messages.get("sys.err.user_pwd_err"));
} else {
throw new XException(messages.get("sys.err"));
}
} else {
throw new XException(messages.get("sys.err.user_pwd_err"));
}
} }
@Override @Override
......
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