mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
Add checkPassword().
This commit is contained in:
@ -55,14 +55,33 @@ func CheckUserSignup(organization string, username string, password string, disp
|
||||
}
|
||||
}
|
||||
|
||||
func checkPassword(user *User, password string) string {
|
||||
if user.PasswordType == "plain" {
|
||||
if password == user.Password {
|
||||
return ""
|
||||
} else {
|
||||
return "password incorrect"
|
||||
}
|
||||
} else if user.PasswordType == "salt" {
|
||||
if getSaltedPassword(password) == user.Password {
|
||||
return ""
|
||||
} else {
|
||||
return "password incorrect"
|
||||
}
|
||||
} else {
|
||||
return fmt.Sprintf("unsupported password type: %s", user.PasswordType)
|
||||
}
|
||||
}
|
||||
|
||||
func CheckUserLogin(organization string, username string, password string) (*User, string) {
|
||||
user := GetUserByFields(organization, username)
|
||||
if user == nil {
|
||||
return nil, "the user does not exist, please sign up first"
|
||||
}
|
||||
|
||||
if user.Password != password {
|
||||
return nil, "password incorrect"
|
||||
msg := checkPassword(user, password)
|
||||
if msg != "" {
|
||||
return nil, msg
|
||||
}
|
||||
|
||||
if user.IsForbidden {
|
||||
|
Reference in New Issue
Block a user