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/
原文地址:https://www.cnblogs.com/haima/p/14735710.html