Skip to content

Commit 7a3152a

Browse files
committed
Fix a bug which prevented creating new users on mysql 5.7.6+ servers (introduced while fixing #2418) (see also #2229)
1 parent 56badea commit 7a3152a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Source/SPUserManager.m

+15-4
Original file line numberDiff line numberDiff line change
@@ -1078,10 +1078,21 @@ - (BOOL)insertUser:(SPUserMO *)user
10781078

10791079
NSString *idString;
10801080
if(requiresPost576PasswordHandling) {
1081-
//copy the hash from the parent. if the parent password changes at the same time, updateUser: will take care of it afterwards
1082-
NSString *plugin = [[[user parent] valueForKey:@"plugin"] tickQuotedString];
1083-
NSString *hash = [[[user parent] valueForKey:@"authentication_string"] tickQuotedString];
1084-
idString = [NSString stringWithFormat:@"IDENTIFIED WITH %@ AS %@",plugin,hash];
1081+
// there are three situations to cover here:
1082+
// 1) host added, parent user unchanged
1083+
// 2) host added, parent user password changed
1084+
// 3) host added, parent user is new
1085+
if([[user parent] valueForKey:@"originaluser"]) {
1086+
// 1 & 2: If the parent user already exists we always use the old password hash. if the parent password changes at the same time, updateUser: will take care of it afterwards
1087+
NSString *plugin = [[[user parent] valueForKey:@"plugin"] tickQuotedString];
1088+
NSString *hash = [[[user parent] valueForKey:@"authentication_string"] tickQuotedString];
1089+
idString = [NSString stringWithFormat:@"IDENTIFIED WITH %@ AS %@",plugin,hash];
1090+
}
1091+
else {
1092+
// 3: If the user is new, we take the plaintext password value from the UI
1093+
NSString *password = [[[user parent] valueForKey:@"password"] tickQuotedString];
1094+
idString = [NSString stringWithFormat:@"IDENTIFIED BY %@",password];
1095+
}
10851096
}
10861097
else {
10871098
BOOL passwordIsHash;

0 commit comments

Comments
 (0)