mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-02 19:40:19 +08:00
feat: Add bcrypt encrypted password type (#386)
* Add loading and countdown status to the verification code sending button
* Add bcrypt encrypted password type
* Revert "Add loading and countdown status to the verification code sending button"
This reverts commit 782b9e229a
.
* Update bcrypt.go
* Update go.sum
This commit is contained in:
23
cred/bcrypt.go
Normal file
23
cred/bcrypt.go
Normal file
@ -0,0 +1,23 @@
|
||||
package cred
|
||||
|
||||
import "golang.org/x/crypto/bcrypt"
|
||||
|
||||
type BcryptCredManager struct{}
|
||||
|
||||
func NewBcryptCredManager() *BcryptCredManager {
|
||||
cm := &BcryptCredManager{}
|
||||
return cm
|
||||
}
|
||||
|
||||
func (cm *BcryptCredManager) GetHashedPassword(password string, userSalt string, organizationSalt string) string {
|
||||
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
func (cm *BcryptCredManager) IsPasswordCorrect(plainPwd string, hashedPwd string, userSalt string, organizationSalt string) bool {
|
||||
err := bcrypt.CompareHashAndPassword([]byte(hashedPwd), []byte(plainPwd))
|
||||
return err == nil
|
||||
}
|
Reference in New Issue
Block a user