service: use database.User.SetPassword instead of bcrypt
This commit is contained in:
parent
4bebe4a1f2
commit
67335130b1
10
service.go
10
service.go
@ -15,7 +15,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
"gopkg.in/irc.v4"
|
"gopkg.in/irc.v4"
|
||||||
|
|
||||||
"git.sr.ht/~emersion/soju/database"
|
"git.sr.ht/~emersion/soju/database"
|
||||||
@ -1032,12 +1031,11 @@ func handleUserUpdate(ctx *serviceContext, params []string) error {
|
|||||||
|
|
||||||
var hashed *string
|
var hashed *string
|
||||||
if password != nil {
|
if password != nil {
|
||||||
hashedBytes, err := bcrypt.GenerateFromPassword([]byte(*password), bcrypt.DefaultCost)
|
var passwordRecord database.User
|
||||||
if err != nil {
|
if err := passwordRecord.SetPassword(*password); err != nil {
|
||||||
return fmt.Errorf("failed to hash password: %v", err)
|
return err
|
||||||
}
|
}
|
||||||
hashedStr := string(hashedBytes)
|
hashed = &passwordRecord.Password
|
||||||
hashed = &hashedStr
|
|
||||||
}
|
}
|
||||||
if disablePassword {
|
if disablePassword {
|
||||||
hashedStr := ""
|
hashedStr := ""
|
||||||
|
Loading…
Reference in New Issue
Block a user