ldap-1-backend/public/tools/util_test.go

40 lines
898 B
Go
Raw Permalink Normal View History

2022-05-18 17:57:03 +08:00
package tools
import (
"fmt"
"testing"
)
func TestGenPass(t *testing.T) {
fmt.Printf("密码为:%s\n", NewGenPasswd("123456"))
// err := ComparePasswd("$2a$10$Fy8p0nCixgWKzLfO3SgdhOzAF7YolSt6dHj6QidDGYlzLJDpniXB6", "123456")
// if err != nil {
// fmt.Printf("密码错误:%s\n", err)
// }
}
2022-05-31 14:08:56 +08:00
func TestArrUintCmp(t *testing.T) {
a := []uint{1, 2, 3, 4, 6, 9}
b := []uint{1, 2, 3, 4, 5, 6, 7}
c, d := ArrUintCmp(a, b)
fmt.Printf("%v\n", c)
fmt.Printf("%v\n", d)
}
func TestSliceToString(t *testing.T) {
a := []uint{1}
fmt.Printf("%s\n", SliceToString(a, ","))
}
func TestEncodePass(t *testing.T) {
// to encode a password into ssha
hashed := EncodePass([]byte("testpass"))
fmt.Println(string(hashed))
// to validate a password against saved hash.
if Matches([]byte(hashed), []byte("testpass")) {
fmt.Println("Its a match.")
} else {
fmt.Println("its not match")
}
}