2021-12-22 13:56:32 +08:00
|
|
|
package cred
|
|
|
|
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
|
|
|
|
type BcryptCredManager struct{}
|
|
|
|
|
|
|
|
func NewBcryptCredManager() *BcryptCredManager {
|
|
|
|
cm := &BcryptCredManager{}
|
|
|
|
return cm
|
|
|
|
}
|
|
|
|
|
2025-07-05 18:41:37 +08:00
|
|
|
func (cm *BcryptCredManager) GetHashedPassword(password string, salt string) string {
|
2021-12-22 13:56:32 +08:00
|
|
|
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
|
|
|
|
}
|