Skip to content

Commit d54f714

Browse files
author
heavyrian2012
committed
升级sdk和添加默认密码
1 parent f0cdb22 commit d54f714

File tree

6 files changed

+31
-5
lines changed

6 files changed

+31
-5
lines changed

config/application.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ wfc.audio.cache.dir=/data/wfc/audio/cache
4848
# 详情请参考 https://www.baidu.com/s?wd=cookie+SameSite&ie=utf-8
4949
wfc.all_client_support_ssl=false
5050

51+
## 是否添加用户默认密码。当使用组织架构服务导入员工信息后,员工无法直接登录。可以开启此配置,使用手机号码的后六位作为初始密码。首次登录之后必须修改密码。其他情况不用打开此开关。
52+
## 用户设置密码时,不能设置为手机号码的后6位
53+
wfc.default_user_password=false
5154

5255
## iOS系统使用share extension来处理分享,客户端无法调用SDK发送消息和文件,只能通过应用服务来进行。
5356
## 这里配置为了满足iOS设备在share extension中进行上传文件的需求。

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2424
<java.version>1.8</java.version>
2525
<log4j2.version>2.17.2</log4j2.version>
26-
<wfc.sdk.version>1.3.2</wfc.sdk.version>
26+
<wfc.sdk.version>1.3.3</wfc.sdk.version>
2727
</properties>
2828

2929
<dependencies>
Binary file not shown.

src/lib/sdk-1.3.2.jar

-148 KB
Binary file not shown.

src/lib/sdk-1.3.3.jar

164 KB
Binary file not shown.

src/main/java/cn/wildfirechat/app/ServiceImpl.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ public class ServiceImpl implements Service {
9696
@Value("${im.admin_url}")
9797
private String adminUrl;
9898

99+
@Value("${wfc.default_user_password}")
100+
private boolean defaultUserPwd;
101+
99102
@Autowired
100103
private ShortUUIDGenerator userNameGenerator;
101104

@@ -343,8 +346,13 @@ public RestResult loginWithMobileCode(HttpServletResponse httpResponse, String m
343346
return onLoginSuccess(httpResponse, mobile, clientId, platform, true);
344347
}
345348

349+
private String getUserDefaultPassword(String mobile) {
350+
return mobile.length()>6?mobile.substring(mobile.length()-6):mobile;
351+
}
352+
346353
@Override
347354
public RestResult loginWithPassword(HttpServletResponse response, String mobile, String password, String clientId, int platform) {
355+
boolean isUseDefaultPwd = false;
348356
try {
349357
IMResult<InputOutputUserInfo> userResult = UserAdmin.getUserByMobile(mobile);
350358
if (userResult.getErrorCode() == ErrorCode.ERROR_CODE_NOT_EXIST) {
@@ -355,9 +363,23 @@ public RestResult loginWithPassword(HttpServletResponse response, String mobile,
355363
return RestResult.error(RestResult.RestCode.ERROR_SERVER_ERROR);
356364
}
357365
Optional<UserPassword> optional = userPasswordRepository.findById(userResult.getResult().getUserId());
366+
String defaultPwd = getUserDefaultPassword(mobile);
358367
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+
}
361383
}
362384
UserPassword up = optional.get();
363385
if (up.getTryCount() > 5) {
@@ -407,7 +429,7 @@ public RestResult loginWithPassword(HttpServletResponse response, String mobile,
407429
return RestResult.error(RestResult.RestCode.ERROR_SERVER_ERROR);
408430
}
409431

410-
return onLoginSuccess(response, mobile, clientId, platform, false);
432+
return onLoginSuccess(response, mobile, clientId, platform, isUseDefaultPwd);
411433
}
412434

413435
@Override
@@ -480,7 +502,7 @@ public RestResult resetPassword(String mobile, String resetCode, String newPwd)
480502
}
481503
}
482504

483-
private void changePassword(UserPassword up, String password) throws Exception {
505+
private UserPassword changePassword(UserPassword up, String password) throws Exception {
484506
MessageDigest digest = MessageDigest.getInstance(Sha1Hash.ALGORITHM_NAME);
485507
digest.reset();
486508
String salt = UUID.randomUUID().toString();
@@ -490,6 +512,7 @@ private void changePassword(UserPassword up, String password) throws Exception {
490512
up.setPassword(hashedPwd);
491513
up.setSalt(salt);
492514
userPasswordRepository.save(up);
515+
return up;
493516
}
494517

495518
private boolean verifyPassword(UserPassword up, String password) throws Exception {

0 commit comments

Comments
 (0)