From 0ac1ebf15c11f4b283a3d8a001b41f568c491876 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 3 Mar 2016 22:38:41 +0100 Subject: Fix an issue where changing a user password and adding a host at the same time would result in a query error (#2427) --- Source/SPUserManager.m | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index a5a83cbe..12da17fb 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -1084,8 +1084,24 @@ static NSString * const SPTableViewNameColumnID = @"NameColumn"; 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]) ? -- cgit v1.2.3