28 lines
563 B
Go
28 lines
563 B
Go
package test
|
|
|
|
import (
|
|
"fmt"
|
|
"golang.org/x/crypto/bcrypt"
|
|
"math/rand"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRain(t *testing.T) {
|
|
rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
verifyCode := fmt.Sprintf("%06v", rand.Int31n(1000000))
|
|
fmt.Println(verifyCode)
|
|
}
|
|
|
|
func TestPwd(t *testing.T) {
|
|
password, _ := bcrypt.GenerateFromPassword([]byte("loser7659"), bcrypt.DefaultCost)
|
|
fmt.Println(string(password))
|
|
|
|
err := bcrypt.CompareHashAndPassword(password, []byte("122456"))
|
|
if err != nil {
|
|
fmt.Println("密码错误")
|
|
} else {
|
|
fmt.Println("密码正确")
|
|
}
|
|
}
|