密码盐值加密
This commit is contained in:
parent
70834b64d1
commit
03942028f4
@ -1,23 +1,18 @@
|
||||
package com.cdzy.staff.controller;
|
||||
|
||||
import com.cdzy.common.enums.Message;
|
||||
import com.cdzy.common.model.request.PageParam;
|
||||
import com.cdzy.common.model.response.JsonResult;
|
||||
import com.cdzy.staff.model.dto.StaffInfo;
|
||||
import com.cdzy.staff.model.entity.EbikeOperatorStaff;
|
||||
import com.cdzy.staff.service.EbikeOperatorStaffService;
|
||||
import com.cdzy.staff.model.vo.StaffVo;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.cdzy.staff.service.EbikeOperatorStaffService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 运营商员工账户表 控制层。
|
||||
*
|
||||
* @author loves
|
||||
* @author attiya
|
||||
* @since 2025-08-08
|
||||
*/
|
||||
@RestController
|
||||
@ -28,54 +23,7 @@ public class EbikeOperatorStaffController {
|
||||
private EbikeOperatorStaffService ebikeOperatorStaffService;
|
||||
|
||||
/**
|
||||
* 添加运营商员工账户表。
|
||||
*
|
||||
* @param ebikeOperatorStaff 运营商员工账户表
|
||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||
*/
|
||||
@PostMapping("save")
|
||||
public JsonResult<?> save(@RequestBody EbikeOperatorStaff ebikeOperatorStaff) {
|
||||
ebikeOperatorStaffService.save(ebikeOperatorStaff);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键删除运营商员工账户表。
|
||||
*
|
||||
* @param id 主键
|
||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||
*/
|
||||
@PostMapping("remove/{id}")
|
||||
public JsonResult<?> remove(@PathVariable Long id) {
|
||||
ebikeOperatorStaffService.removeById(id);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主键更新运营商员工账户表。
|
||||
*
|
||||
* @param ebikeOperatorStaff 运营商员工账户表
|
||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||
*/
|
||||
@PostMapping("update")
|
||||
public JsonResult<?> update(@RequestBody EbikeOperatorStaff ebikeOperatorStaff) {
|
||||
ebikeOperatorStaffService.updateById(ebikeOperatorStaff);
|
||||
return JsonResult.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询所有运营商员工账户表。
|
||||
*
|
||||
* @return 所有数据
|
||||
*/
|
||||
@GetMapping("list")
|
||||
public JsonResult<?> list() {
|
||||
List<EbikeOperatorStaff> list = ebikeOperatorStaffService.list();
|
||||
return JsonResult.success(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据运营商员工账户表主键获取详细信息。
|
||||
* 获取当前登陆账号详情
|
||||
*
|
||||
* @return 运营商员工账户表详情
|
||||
*/
|
||||
@ -85,18 +33,6 @@ public class EbikeOperatorStaffController {
|
||||
return JsonResult.success(info);
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询运营商员工账户表。
|
||||
*
|
||||
* @param pageParam 分页对象
|
||||
* @return 分页对象
|
||||
*/
|
||||
@GetMapping("page")
|
||||
public JsonResult<?> page(PageParam pageParam) {
|
||||
Page<EbikeOperatorStaff> page = ebikeOperatorStaffService.page(pageParam.getPage());
|
||||
return JsonResult.success(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* 运营商员工登录。
|
||||
*
|
||||
@ -108,4 +44,16 @@ public class EbikeOperatorStaffController {
|
||||
String token = ebikeOperatorStaffService.login(staffVo);
|
||||
return JsonResult.success(Message.LOGIN,token);
|
||||
}
|
||||
|
||||
/**
|
||||
* 运营商员工登录。
|
||||
*
|
||||
* @param staffVo 登录信息
|
||||
* @return 结果
|
||||
*/
|
||||
@PostMapping("add")
|
||||
public JsonResult<?> add(@Validated @RequestBody StaffVo staffVo) {
|
||||
ebikeOperatorStaffService.add(staffVo);
|
||||
return JsonResult.success(Message.ADD_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,6 +36,8 @@ public class EbikeOperatorStaff implements Serializable {
|
||||
|
||||
private String password;
|
||||
|
||||
private String salt;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Long operatorId;
|
||||
|
||||
@ -16,4 +16,6 @@ public interface EbikeOperatorStaffService extends IService<EbikeOperatorStaff>
|
||||
String login(StaffVo staffVo);
|
||||
|
||||
StaffInfo getStaffInfo();
|
||||
|
||||
void add(StaffVo staffVo);
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package com.cdzy.staff.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.ex.EbikeException;
|
||||
import com.cdzy.common.utils.SHA256WithSaltUtil;
|
||||
import com.cdzy.staff.model.dto.StaffInfo;
|
||||
import com.cdzy.staff.model.entity.EbikeOperatorStaff;
|
||||
import com.cdzy.staff.mapper.EbikeOperatorStaffMapper;
|
||||
@ -37,7 +38,10 @@ public class EbikeOperatorStaffServiceImpl extends ServiceImpl<EbikeOperatorStaf
|
||||
if (ebikeOperatorStaff == null) {
|
||||
throw new EbikeException("用户名错误");
|
||||
} else {
|
||||
boolean equals = ebikeOperatorStaff.getPassword().equals(staffVo.getPassword());
|
||||
String salt = ebikeOperatorStaff.getSalt();
|
||||
String password = staffVo.getPassword();
|
||||
password = SHA256WithSaltUtil.encrypt(password, salt);
|
||||
boolean equals = ebikeOperatorStaff.getPassword().equals(password);
|
||||
if (!equals) {
|
||||
throw new EbikeException("密码错误");
|
||||
} else {
|
||||
@ -65,4 +69,19 @@ public class EbikeOperatorStaffServiceImpl extends ServiceImpl<EbikeOperatorStaf
|
||||
.permissions(permissions)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(StaffVo staffVo) {
|
||||
QueryWrapper queryWrapper = QueryWrapper.create()
|
||||
.where(EBIKE_OPERATOR_STAFF.USERNAME.eq(staffVo.getUsername()));
|
||||
EbikeOperatorStaff ebikeOperatorStaff = staffMapper.selectOneByQuery(queryWrapper);
|
||||
if (ebikeOperatorStaff == null) {
|
||||
throw new EbikeException("用户名错误");
|
||||
} else {
|
||||
String salt = SHA256WithSaltUtil.generateSalt();
|
||||
String password = staffVo.getPassword();
|
||||
password = SHA256WithSaltUtil.encrypt(password, salt);
|
||||
//TODO:添加用户账号密码与对应权限
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ spring:
|
||||
max-lifetime: 1800000
|
||||
sql:
|
||||
init:
|
||||
platform: mysql
|
||||
platform: postgis
|
||||
mode: always
|
||||
schema-locations: classpath:db/init.sql
|
||||
data-locations: classpath:db/data.sql
|
||||
|
||||
@ -14,6 +14,7 @@ public class PasswordTest {
|
||||
String password = "123456";
|
||||
String encrypt = SHA256WithSaltUtil.encrypt(password, salt);
|
||||
System.out.println(encrypt);
|
||||
System.out.println(encrypt.length());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user