Skip to content

Commit 0ac1ebf

Browse files
committed
Fix an issue where changing a user password and adding a host at the same time would result in a query error (#2427)
1 parent bff1773 commit 0ac1ebf

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

Source/SPUserManager.m

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff 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]) ?

0 commit comments

Comments
 (0)