Commit 4a832442 authored by Quxl's avatar Quxl

优化登陆校验,密码加密

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