Golang重复Rails Devise gem密码加密

https://github.com/haimait/go-devise-encryptor

package main

import (
	"fmt"
	//devisecrypto "haimait/learn/testdevise/go-devise-encryptor"
	"github.com/consyse/go-devise-encryptor"
)

func main() {
	password := "changeme"
	stretches := 10
	pepper := ""
	//pepper := "a really bad pepper"

	// tip 创建密码
	hashedPassword, err := devisecrypto.Digest(password, stretches, pepper)
	if err != nil {
		panic(err)
	}
	fmt.Println("hashedPassword: ", hashedPassword)

	// and to compare with a previously hashed password

	newPassword := "changeme"
	// tip 校验密码
	val := devisecrypto.Compare(newPassword, pepper, hashedPassword)

	if val {
		fmt.Println("Passwords are the same ")
	} else {
		fmt.Println("Passwords failed ")
	}

}

[Haima的博客] http://www.cnblogs.com/haima/
posted @ 2021-05-06 16:22  HaimaBlog  阅读(35)  评论(0编辑  收藏  举报