Реализована лабораторная 6 на оценку 4

This commit is contained in:
MacBook
2026-11-16 15:16:54 +03:00
parent 470d9d6f1e
commit 4262a16ada
64 changed files with 8467 additions and 43 deletions
+33
View File
@@ -0,0 +1,33 @@
package messenger
import (
"strings"
"testing"
)
func TestPasswordHash(t *testing.T) {
const password = "long-test-password"
first, err := hashPassword(password)
if err != nil {
t.Fatal(err)
}
second, err := hashPassword(password)
if err != nil {
t.Fatal(err)
}
if first == password || strings.Contains(first, password) {
t.Fatal("hash contains the original password")
}
if first == second {
t.Fatal("independent hashes must use different salts")
}
if !verifyPassword(first, password) {
t.Fatal("correct password was rejected")
}
if verifyPassword(first, "wrong-test-password") {
t.Fatal("wrong password was accepted")
}
if verifyPassword("damaged-hash", password) {
t.Fatal("malformed hash was accepted")
}
}