File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1084,8 +1084,24 @@ - (BOOL)insertUser:(SPUserMO *)user
10841084 idString = [NSString stringWithFormat: @" IDENTIFIED WITH %@ AS %@ " ,plugin,hash];
10851085 }
10861086 else {
1087- NSString *password = [[[user parent ] valueForKey: @" password" ] tickQuotedString ];
1088- idString = [NSString stringWithFormat: @" IDENTIFIED BY %@%@ " ,[[user parent ] valueForKey: @" originaluser" ]?@" PASSWORD " :@" " , password];
1087+ BOOL passwordIsHash;
1088+ NSString *password;
1089+ // there are three situations to cover here:
1090+ // 1) host added, parent user unchanged
1091+ // 2) host added, parent user password changed
1092+ // 3) host added, parent user is new
1093+ if ([[user parent ] valueForKey: @" originaluser" ]) {
1094+ // 1 & 2: If the parent user already exists we always use the old password hash.
1095+ // This works because -updateUser: will be called after -insertUser: and update the password for this host, anyway.
1096+ passwordIsHash = YES ;
1097+ password = [[[user parent ] valueForKey: @" originalpassword" ] tickQuotedString ];
1098+ }
1099+ else {
1100+ // 3: If the user is new, we take the plaintext password value from the UI
1101+ passwordIsHash = NO ;
1102+ password = [[[user parent ] valueForKey: @" password" ] tickQuotedString ];
1103+ }
1104+ idString = [NSString stringWithFormat: @" IDENTIFIED BY %@%@ " ,(passwordIsHash? @" PASSWORD " : @" " ), password];
10891105 }
10901106
10911107 createStatement = ([serverSupport supportsCreateUser ]) ?
You can’t perform that action at this time.
0 commit comments