first commit

This commit is contained in:
Sas Andy
2024-12-09 09:51:19 +07:00
commit ecc5dfd9c0
69 changed files with 5365 additions and 0 deletions

29
services/auth/password.go Normal file
View File

@@ -0,0 +1,29 @@
package auth
import (
"crypto/md5"
"encoding/hex"
"golang.org/x/crypto/bcrypt"
)
func HashPassword(password string) (string, error) {
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
if err != nil {
return "", err
}
return string(hash), nil
}
func ComparePasswords(hashed string, plain []byte) bool {
err := bcrypt.CompareHashAndPassword([]byte(hashed), plain)
return err == nil
}
func HashWithMD5(password string) string {
salt := "545"
data := []byte(salt + password + salt)
hash := md5.Sum(data)
return hex.EncodeToString(hash[:])
}