mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2024-10-30 03:36:16 +00:00
implement changing user password function
This commit is contained in:
parent
6c2a3c9745
commit
b41acf1f57
15
user/user.go
15
user/user.go
@ -1,6 +1,7 @@
|
|||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
@ -135,6 +136,20 @@ func (user *User) ShowLockMaybe(w http.ResponseWriter, rq *http.Request) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sets a new password for the user.
|
||||||
|
func (user *User) ChangePassword(password string) error {
|
||||||
|
if user.Source != "local" {
|
||||||
|
return fmt.Errorf("Only local users can change their passwords.")
|
||||||
|
}
|
||||||
|
|
||||||
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
user.Password = string(hash)
|
||||||
|
return SaveUserDatabase()
|
||||||
|
}
|
||||||
|
|
||||||
// IsValidUsername checks if the given username is valid.
|
// IsValidUsername checks if the given username is valid.
|
||||||
func IsValidUsername(username string) bool {
|
func IsValidUsername(username string) bool {
|
||||||
for _, r := range username {
|
for _, r := range username {
|
||||||
|
Loading…
Reference in New Issue
Block a user