feat: auth, site creation with PHP version selection

This commit is contained in:
orohi
2026-06-17 04:46:44 +03:00
parent 0f31c24bf9
commit b7753505b8
20 changed files with 1097 additions and 114 deletions
+34
View File
@@ -0,0 +1,34 @@
package auth
import (
"crypto/rand"
"crypto/sha256"
"encoding/hex"
"errors"
"golang.org/x/crypto/bcrypt"
)
var ErrInvalidCredentials = errors.New("invalid credentials")
func CheckPassword(hash, password string) error {
if err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)); err != nil {
return ErrInvalidCredentials
}
return nil
}
func NewSessionToken() (raw string, hash string, err error) {
b := make([]byte, 32)
if _, err = rand.Read(b); err != nil {
return "", "", err
}
raw = hex.EncodeToString(b)
hash = HashToken(raw)
return raw, hash, nil
}
func HashToken(raw string) string {
sum := sha256.Sum256([]byte(raw))
return hex.EncodeToString(sum[:])
}