15357fd3c0
yalarbacreate and moove into new directories for BegushiyBashkir and yalarbacreate and moove into new directories for BegushiyBashkir and yalarbacreate and moove into new directories for BegushiyBashkir and yalarbacreate and moove into new directories for BegushiyBashkir and yalarbacreate and moove into new directories for BegushiyBashkir and yalarbacreate and moove into new directories for BegushiyBashkir and yalarbacreate and moove into new directories for BegushiyBashkir and yalarbacreate and moove into new directories for BegushiyBashkir and yalarba
30 lines
823 B
Go
30 lines
823 B
Go
// utils/password.go
|
|
package utils
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/base64"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
func HashPassword(password string) (string, error) {
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
return string(bytes), err
|
|
}
|
|
|
|
func CheckPasswordHash(password, hash string) bool {
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
return err == nil
|
|
}
|
|
|
|
// GenerateRandomPassword генерирует случайный пароль для OAuth пользователей
|
|
func GenerateRandomPassword() string {
|
|
bytes := make([]byte, 32) // 256 бит
|
|
_, err := rand.Read(bytes)
|
|
if err != nil {
|
|
// Fallback - используем временный пароль
|
|
return "temp_oauth_password_123"
|
|
}
|
|
return base64.URLEncoding.EncodeToString(bytes)
|
|
}
|