Add checkPassword().

This commit is contained in:
Yang Luo
2021-05-03 10:13:32 +08:00
parent 6e47cd5bd5
commit 6095af0512
2 changed files with 21 additions and 3 deletions

View File

@ -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) { func CheckUserLogin(organization string, username string, password string) (*User, string) {
user := GetUserByFields(organization, username) user := GetUserByFields(organization, username)
if user == nil { if user == nil {
return nil, "the user does not exist, please sign up first" return nil, "the user does not exist, please sign up first"
} }
if user.Password != password { msg := checkPassword(user, password)
return nil, "password incorrect" if msg != "" {
return nil, msg
} }
if user.IsForbidden { if user.IsForbidden {

View File

@ -24,7 +24,6 @@ import * as Setting from "../Setting";
import {GithubLoginButton, GoogleLoginButton} from "react-social-login-buttons"; import {GithubLoginButton, GoogleLoginButton} from "react-social-login-buttons";
import QqLoginButton from "./QqLoginButton"; import QqLoginButton from "./QqLoginButton";
import i18next from "i18next"; import i18next from "i18next";
import {authConfig} from "./Auth";
class LoginPage extends React.Component { class LoginPage extends React.Component {
constructor(props) { constructor(props) {