Skip to content
Permalink
Browse files

Fix an issue where changing a user password and adding a host at the …

…same time would result in a query error (#2427)
  • Loading branch information...
dmoagx committed Mar 3, 2016
1 parent bff1773 commit 0ac1ebf15c11f4b283a3d8a001b41f568c491876
Showing with 18 additions and 2 deletions.
  1. +18 −2 Source/SPUserManager.m
@@ -1084,8 +1084,24 @@ - (BOOL)insertUser:(SPUserMO *)user
idString = [NSString stringWithFormat:@"IDENTIFIED WITH %@ AS %@",plugin,hash];
}
else {
NSString *password = [[[user parent] valueForKey:@"password"] tickQuotedString];
idString = [NSString stringWithFormat:@"IDENTIFIED BY %@%@",[[user parent] valueForKey:@"originaluser"]?@"PASSWORD ":@"", password];
BOOL passwordIsHash;
NSString *password;
// there are three situations to cover here:
// 1) host added, parent user unchanged
// 2) host added, parent user password changed
// 3) host added, parent user is new
if([[user parent] valueForKey:@"originaluser"]) {
// 1 & 2: If the parent user already exists we always use the old password hash.
// This works because -updateUser: will be called after -insertUser: and update the password for this host, anyway.
passwordIsHash = YES;
password = [[[user parent] valueForKey:@"originalpassword"] tickQuotedString];
}
else {
// 3: If the user is new, we take the plaintext password value from the UI
passwordIsHash = NO;
password = [[[user parent] valueForKey:@"password"] tickQuotedString];
}
idString = [NSString stringWithFormat:@"IDENTIFIED BY %@%@",(passwordIsHash? @"PASSWORD " : @""), password];
}

createStatement = ([serverSupport supportsCreateUser]) ?

0 comments on commit 0ac1ebf

Please sign in to comment.
You can’t perform that action at this time.