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

This commit is contained in:
MacBook
2026-11-03 14:05:38 +03:00
parent 276dbdad8a
commit 9db2fa724a
41 changed files with 4267 additions and 37 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")
}
}