1、生成密码并入库保存
String id= SnowflakeIdUtil.nextValue();//生成id operatCompany.setId(id); String salt = oConvertUtils.randomGen(8);//生成密码盐 operatCompany.setSalt(salt); String resetPasswd= ConfigManager.getInstance().GetProperty("resetPasswd");//读取配置文件的默认密码 String passwordEncode = PasswordUtil.encrypt(id, resetPasswd, salt);//根据id+密码+密码盐,生成加密密码(这里id可以换成用户名) operatCompany.setPassword(passwordEncode); operatCompanyService.save(operatCompany);
2、验证密码完成登录
//2. 校验用户名或密码是否正确 String userpassword = PasswordUtil.encrypt(id, password, db_salt); if (!db_password.equals(userpassword)) { result.error500("用户名或密码错误"); return result; }
3、密码修改
String passwordEncode = PasswordUtil.encrypt(os.getId(), password, os.getSalt()); operatStaffService.update(new OperatStaff().setPassword(passwordEncode),new LambdaQueryWrapper<OperatStaff>().eq(oConvertUtils.isNotEmpty(username),OperatStaff::getMobile, username));