Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions enginetest/queries/priv_auth_queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -2268,6 +2268,24 @@ FROM ((SELECT 1 as found FROM information_schema.tables WHERE table_schema = 'te
},
},
},
{
Name: "Test user creation with hashed password",
SetUpScript: []string{
"CREATE USER 'lol'@'%' IDENTIFIED WITH mysql_native_password AS '*91D9861DFC07DD967611B8C96953474EF270AD5E';",
},
Assertions: []UserPrivilegeTestAssertion{
{
Query: "SELECT User, plugin, authentication_string FROM mysql.user WHERE User = 'lol';",
Expected: []sql.Row{
{
"lol", // User
"mysql_native_password", // plugin
"*91D9861DFC07DD967611B8C96953474EF270AD5E", // authentication_string
},
},
},
},
},
}

// NoopPlaintextPlugin is used to authenticate plaintext user plugins
Expand Down
8 changes: 6 additions & 2 deletions sql/plan/create_user_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,20 @@ func NewDefaultAuthentication(password string) Authentication {
type AuthenticationOther struct {
password string
plugin string
identity string
}

func NewOtherAuthentication(password, plugin string) Authentication {
return AuthenticationOther{password, plugin}
func NewOtherAuthentication(password, plugin, identity string) Authentication {
return AuthenticationOther{password, plugin, identity}
}

func (a AuthenticationOther) Plugin() string {
return a.plugin
}

func (a AuthenticationOther) Password() string {
if a.password == "" {
return a.identity
}
return string(a.password)
}
2 changes: 1 addition & 1 deletion sql/planbuilder/priv.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (b *Builder) buildAuthenticatedUser(user ast.AccountWithAuth) plan.Authenti
if user.Auth1.Plugin == "mysql_native_password" && len(user.Auth1.Password) > 0 {
authUser.Auth1 = plan.AuthenticationMysqlNativePassword(user.Auth1.Password)
} else if len(user.Auth1.Plugin) > 0 {
authUser.Auth1 = plan.NewOtherAuthentication(user.Auth1.Password, user.Auth1.Plugin)
authUser.Auth1 = plan.NewOtherAuthentication(user.Auth1.Password, user.Auth1.Plugin, user.Auth1.Identity)
} else {
// We default to using the password, even if it's empty
authUser.Auth1 = plan.NewDefaultAuthentication(user.Auth1.Password)
Expand Down