Initial commit

This commit is contained in:
George Suntres
2026-03-29 12:31:04 -04:00
commit ec429adb87
11 changed files with 899 additions and 0 deletions

33
encrypt.go Normal file
View File

@@ -0,0 +1,33 @@
package persist
import (
"log"
// "unsafe"
"golang.org/x/crypto/bcrypt"
)
// EncryptPassword will encrypt the password and replace the old one. Will return the encrypted password.
func (user *User) EncryptPassword() string {
if user.Password == "" {
log.Println("Nothing to encrypt.")
return ""
}
hpass, err := bcrypt.GenerateFromPassword([]byte(user.Password), 10)
if err != nil {
log.Fatal(err)
}
user.Password = string(hpass)
return user.Password
}
// CheckPassword returns true if passwords match.
func (user *User) CheckPassword(password string) bool {
err := bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(password))
return err == nil
}