这是一个Java方法,名为doLogin,接收两个参数:userAccount(用户账号)和userPassword(用户密码)。返回值类型为Yupi1。
public Yupi1 doLogin(String userAccount, String userPassword) { // 在这里实现登录逻辑 }


- /**
- *
- * @param userAccount 用户账户
- * @param userPassword 用户密码
- * @return 脱敏后的用户信息
- */
- Yupi1 doLogin(String userAccount,String userPassword);

此处直接顺着敲击










- // 1.校验 账户、密码、校验码 是否包含任何真空值(包含空格或空值)
- // if (true 里面任意一个字段:包含空格或空值) return -1; 就失败了
- if(StringUtils.isAnyBlank(userAccount,userPassword))
- {
- return null;
- }
- if (userAccount.length() < 4)
- {
- return null;
- }
- if (userPassword.length() < 8 )
- {
- return null;
- }
-
- // 账户不能包含特殊字符
- // m.find();//返回true 输入的账户有 特殊字符,需重新输入
- String validPattern = "[`~!@#$%^&*()+=|{}':;',\\\\[\\\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]";
- Matcher matcher = Pattern.compile(validPattern).matcher(userAccount);
- if (matcher.find())
- {
- return null;
- }
-
- // 3.对密码进行加密(密码千万不要直接以明文存储到数据库中)
- // 写代码前,已测试
- /**
- * 在本项目,test 文件夹下,UserCenterApplicationTests 里面书写代码,运行测试的
- *
- * @Test
- * void testDigest() throws NoSuchAlgorithmException{
- * String newPassword = DigestUtils.md5DigestAsHex(("abcd" + "mypassword").getBytes());
- * System.out.println(newPassword);
- * }
- *
- * 运行成功 输出为:(16进制)【可变】78e3504a70116aa7474d614b517809c6
- *
- */
-
- String encryptPassword = DigestUtils.md5DigestAsHex((sAlt + userPassword).getBytes());
-
- //查询用户是否存在,以及判断密码是否等于加密后的算法
- QueryWrapper<Yupi1> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("userAccount",userAccount);
- queryWrapper.eq("userPassword",encryptPassword);
- Yupi1 yupi1 = yupi1Mapper.selectOne(queryWrapper);
- if (yupi1 == null) {
- log.info("user Login failed, userAccount cannot match userPassword");
- return null;
- }
-
- long count = yupi1Mapper.selectCount(queryWrapper);
-
- return null;