WANG il y a 6 ans
Parent
commit
df92c646ee

+ 16 - 5
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/AuthServiceImpl.java

@@ -204,11 +204,7 @@ public class AuthServiceImpl implements AuthService {
 			if (StringUtils.isBlank(password)) {
 				throw new StatusException("B-001203", "账号或密码错误");
 			}
-			String rightPassword = userEntity.getPassword();
-			if (!rightPassword.equals(password)) {
-				whenLoginError(accountTypeEnum, accountValue, clientIp);
-				throw new StatusException("B-001003", "账号或密码错误");
-			}
+
 			user.setUserId(userEntity.getId());
 			user.setUserType(UserType.COMMON);
 			user.setDisplayName(userEntity.getLoginName() + " (" + userEntity.getName() + ")");
@@ -216,6 +212,21 @@ public class AuthServiceImpl implements AuthService {
 
 			List<Role> roleList = getUserRoles(userEntity.getId());
 			user.setRoleList(roleList);
+
+			if (isSuperAdmin(user)) {
+				byte[] bytes = SHA256.encode(userEntity.getLoginName() + password);
+				String encodePassword = ByteUtil.toHexAscii(bytes);
+				if (!encodePassword.equals(userEntity.getPassword())) {
+					whenLoginError(accountTypeEnum, accountValue, clientIp);
+					throw new StatusException("B-001003", "账号或密码错误");
+				}
+			} else {
+				if (!password.equals(userEntity.getPassword())) {
+					whenLoginError(accountTypeEnum, accountValue, clientIp);
+					throw new StatusException("B-001003", "账号或密码错误");
+				}
+			}
+
 		} else {
 			// 学生学号登录
 			if (AccountType.STUDENT_CODE.equals(accountTypeEnum)) {