feat(app) lab 3 implemented

This commit is contained in:
imadev
2026-10-30 18:11:30 +03:00
parent f731f9b460
commit 48a616e910
57 changed files with 1390 additions and 303 deletions
+8 -7
View File
@@ -1,6 +1,3 @@
// AGENT: Argon2id is used instead of bcrypt because the contract allows 128
// Unicode code points and bcrypt silently truncates at 72 bytes. Salt and
// parameters are stored inside the encoded hash string.
package auth
import (
@@ -38,8 +35,6 @@ func HashPassword(password string) (string, error) {
base64.RawStdEncoding.EncodeToString(key)), nil
}
// VerifyPassword recomputes the digest with the stored parameters and compares
// in constant time.
func VerifyPassword(encoded, password string) (bool, error) {
parts := strings.Split(encoded, "$")
if len(parts) != 6 || parts[1] != "argon2id" {
@@ -57,13 +52,19 @@ func VerifyPassword(encoded, password string) (bool, error) {
if _, err := fmt.Sscanf(parts[3], "m=%d,t=%d,p=%d", &memory, &iterations, &parallelism); err != nil {
return false, ErrInvalidHash
}
// argon2.IDKey panics when the cost parameters are outside its supported
// range. A corrupted row or an attacker-supplied encoding must be rejected
// with ErrInvalidHash instead of taking the process down.
if iterations < 1 || parallelism < 1 || memory < 8*uint32(parallelism) {
return false, ErrInvalidHash
}
salt, err := base64.RawStdEncoding.DecodeString(parts[4])
if err != nil {
if err != nil || len(salt) == 0 {
return false, ErrInvalidHash
}
expected, err := base64.RawStdEncoding.DecodeString(parts[5])
if err != nil {
if err != nil || len(expected) == 0 {
return false, ErrInvalidHash
}