modified: go.mod
modified: go.sum new file: internal/config/oauth.go new file: internal/handler/auth.go new file: internal/utils/errors.go new file: internal/utils/json.go modified: internal/utils/password.go Add utils, add auth handler, auth configs
This commit is contained in:
@@ -1,14 +1,29 @@
|
||||
// utils/password.go
|
||||
package utils
|
||||
|
||||
import "golang.org/x/crypto/bcrypt"
|
||||
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
|
||||
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
|
||||
}
|
||||
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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user