@@ -136,8 +136,7 @@ IDepartmentRepository departmentRepository
136136 return ( null , errorMessage ) ;
137137 }
138138
139- var passwordSalt = GenerateSalt ( ) ;
140- password = EncodePassword ( password , PasswordFormat . SM4 , passwordSalt ) ;
139+ password = EncodePassword ( password , PasswordFormat . SM4 , out var passwordSalt ) ;
141140 user . LastActivityDate = DateTime . Now ;
142141 user . LastResetPasswordDate = DateTime . Now ;
143142
@@ -155,8 +154,7 @@ public async Task<int> InsertWithoutValidationAsync(User user, string password)
155154 user . Mobile = user . UserName ;
156155 }
157156
158- var passwordSalt = GenerateSalt ( ) ;
159- password = EncodePassword ( password , PasswordFormat . SM4 , passwordSalt ) ;
157+ password = EncodePassword ( password , PasswordFormat . SM4 , out var passwordSalt ) ;
160158 user . LastActivityDate = DateTime . Now ;
161159 user . LastResetPasswordDate = DateTime . Now ;
162160
@@ -263,16 +261,19 @@ await _repository.UpdateAsync(Q
263261 ) ;
264262 }
265263
266- private static string EncodePassword ( string password , PasswordFormat passwordFormat , string passwordSalt )
264+ private static string EncodePassword ( string password , PasswordFormat passwordFormat , out string passwordSalt )
267265 {
268266 var retVal = string . Empty ;
267+ passwordSalt = string . Empty ;
269268
270269 if ( passwordFormat == PasswordFormat . Clear )
271270 {
272271 retVal = password ;
273272 }
274273 else if ( passwordFormat == PasswordFormat . Hashed )
275274 {
275+ passwordSalt = GenerateSalt ( ) ;
276+
276277 var src = Encoding . Unicode . GetBytes ( password ) ;
277278 var buffer2 = Convert . FromBase64String ( passwordSalt ) ;
278279 var dst = new byte [ buffer2 . Length + src . Length ] ;
@@ -341,8 +342,7 @@ private static string GenerateSalt()
341342 return ( false , $ "密码不符合规则,请包含{ config . UserPasswordRestriction . GetDisplayName ( ) } ") ;
342343 }
343344
344- var passwordSalt = GenerateSalt ( ) ;
345- password = EncodePassword ( password , PasswordFormat . SM4 , passwordSalt ) ;
345+ password = EncodePassword ( password , PasswordFormat . SM4 , out var passwordSalt ) ;
346346 await ChangePasswordAsync ( userId , PasswordFormat . SM4 , passwordSalt , password ) ;
347347 return ( true , string . Empty ) ;
348348 }
0 commit comments