@@ -96,6 +96,9 @@ public class ServiceImpl implements Service {
96
96
@ Value ("${im.admin_url}" )
97
97
private String adminUrl ;
98
98
99
+ @ Value ("${wfc.default_user_password}" )
100
+ private boolean defaultUserPwd ;
101
+
99
102
@ Autowired
100
103
private ShortUUIDGenerator userNameGenerator ;
101
104
@@ -343,8 +346,13 @@ public RestResult loginWithMobileCode(HttpServletResponse httpResponse, String m
343
346
return onLoginSuccess (httpResponse , mobile , clientId , platform , true );
344
347
}
345
348
349
+ private String getUserDefaultPassword (String mobile ) {
350
+ return mobile .length ()>6 ?mobile .substring (mobile .length ()-6 ):mobile ;
351
+ }
352
+
346
353
@ Override
347
354
public RestResult loginWithPassword (HttpServletResponse response , String mobile , String password , String clientId , int platform ) {
355
+ boolean isUseDefaultPwd = false ;
348
356
try {
349
357
IMResult <InputOutputUserInfo > userResult = UserAdmin .getUserByMobile (mobile );
350
358
if (userResult .getErrorCode () == ErrorCode .ERROR_CODE_NOT_EXIST ) {
@@ -355,9 +363,23 @@ public RestResult loginWithPassword(HttpServletResponse response, String mobile,
355
363
return RestResult .error (RestResult .RestCode .ERROR_SERVER_ERROR );
356
364
}
357
365
Optional <UserPassword > optional = userPasswordRepository .findById (userResult .getResult ().getUserId ());
366
+ String defaultPwd = getUserDefaultPassword (mobile );
358
367
if (!optional .isPresent ()) {
359
- //当用户不存在或者密码不存在时,返回密码错误。避免被攻击遍历登录获取用户名。
360
- return RestResult .error (ERROR_CODE_INCORRECT );
368
+ if (defaultUserPwd ) {
369
+ UserPassword up = new UserPassword (userResult .getResult ().getUserId ());
370
+ up = changePassword (up , defaultPwd );
371
+ optional = Optional .of (up );
372
+ isUseDefaultPwd = true ;
373
+ } else {
374
+ //当用户不存在或者密码不存在时,返回密码错误。避免被攻击遍历登录获取用户名。
375
+ return RestResult .error (ERROR_CODE_INCORRECT );
376
+ }
377
+ } else {
378
+ if (defaultUserPwd ) {
379
+ if (defaultPwd .equals (password )) {
380
+ isUseDefaultPwd = true ;
381
+ }
382
+ }
361
383
}
362
384
UserPassword up = optional .get ();
363
385
if (up .getTryCount () > 5 ) {
@@ -407,7 +429,7 @@ public RestResult loginWithPassword(HttpServletResponse response, String mobile,
407
429
return RestResult .error (RestResult .RestCode .ERROR_SERVER_ERROR );
408
430
}
409
431
410
- return onLoginSuccess (response , mobile , clientId , platform , false );
432
+ return onLoginSuccess (response , mobile , clientId , platform , isUseDefaultPwd );
411
433
}
412
434
413
435
@ Override
@@ -480,7 +502,7 @@ public RestResult resetPassword(String mobile, String resetCode, String newPwd)
480
502
}
481
503
}
482
504
483
- private void changePassword (UserPassword up , String password ) throws Exception {
505
+ private UserPassword changePassword (UserPassword up , String password ) throws Exception {
484
506
MessageDigest digest = MessageDigest .getInstance (Sha1Hash .ALGORITHM_NAME );
485
507
digest .reset ();
486
508
String salt = UUID .randomUUID ().toString ();
@@ -490,6 +512,7 @@ private void changePassword(UserPassword up, String password) throws Exception {
490
512
up .setPassword (hashedPwd );
491
513
up .setSalt (salt );
492
514
userPasswordRepository .save (up );
515
+ return up ;
493
516
}
494
517
495
518
private boolean verifyPassword (UserPassword up , String password ) throws Exception {
0 commit comments