Add PasswordSalt to org.

This commit is contained in:
Yang Luo
2021-05-05 23:40:18 +08:00
parent f442f11568
commit 8a4311c85c
10 changed files with 28 additions and 21 deletions

View File

@ -65,7 +65,7 @@ func checkPassword(user *User, password string) string {
return "password incorrect"
}
} else if organization.PasswordType == "salt" {
if getSaltedPassword(password) == user.Password {
if getSaltedPassword(password, organization.PasswordSalt) == user.Password {
return ""
} else {
return "password incorrect"

View File

@ -1,17 +0,0 @@
// Copyright 2021 The casbin Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package object
var salt = "123"

View File

@ -28,6 +28,7 @@ type Organization struct {
WebsiteUrl string `xorm:"varchar(100)" json:"websiteUrl"`
Favicon string `xorm:"varchar(100)" json:"favicon"`
PasswordType string `xorm:"varchar(100)" json:"passwordType"`
PasswordSalt string `xorm:"varchar(100)" json:"passwordSalt"`
}
func GetOrganizations(owner string) []*Organization {

View File

@ -30,7 +30,7 @@ func getSha256HexDigest(s string) string {
return res
}
func getSaltedPassword(password string) string {
func getSaltedPassword(password string, salt string) string {
hash1 := getSha256HexDigest(password)
res := getSha256HexDigest(hash1 + salt)
return res

View File

@ -47,5 +47,6 @@ func TestSyncIds(t *testing.T) {
func TestGetSaltedPassword(t *testing.T) {
password := "123456"
fmt.Printf("%s -> %s\n", password, getSaltedPassword(password))
salt := "123"
fmt.Printf("%s -> %s\n", password, getSaltedPassword(password, salt))
}