42 lines
662 B
Go
42 lines
662 B
Go
package utils
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
//hashed := fmt.Sprintf("%x", sha256.Sum256([]byte("pa$$word"+"drivelinked")))
|
|
var hashed = "2bd6e406749d3fb8ff5c164ee63c4fdc744164f7327ea3ad6abef90df4e64d03"
|
|
|
|
func TestGenPasswd(t *testing.T) {
|
|
passwd, err := GenPasswd(hashed)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
t.Log(passwd)
|
|
}
|
|
|
|
func TestCheckPasswd(t *testing.T) {
|
|
passwd, err := GenPasswd(hashed)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
// 匹配
|
|
match, err := CheckPasswd(hashed, passwd)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if !match {
|
|
t.Fail()
|
|
}
|
|
|
|
// 不匹配
|
|
match, err = CheckPasswd("abc", passwd)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
if match {
|
|
t.Fail()
|
|
}
|
|
}
|