linux-auth/internal/utils/hash.go

26 lines
685 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"crypto/sha256"
"encoding/hex"
)
/**
* @brief Вычислить SHA-256 хеш пароля
* @param password Строка с паролем
* @return Хеш в виде строки HEX
*/
func HashPassword(password string) string {
hash := sha256.Sum256([]byte(password))
return hex.EncodeToString(hash[:])
}
/**
* @brief Проверить совпадение пароля и хеша
* @param password Введённый пароль
* @param hash Хеш пароля из БД
* @return true если совпадает
*/
func CheckPassword(password, hash string) bool {
return HashPassword(password) == hash
}