Commit 3ca23f52 authored by shajiaiming's avatar shajiaiming

Merge branch 'feature/manage-user' into 'develop'

钱包用户管理 See merge request !2
parents 46d148f2 54276faa
......@@ -16,4 +16,6 @@ const (
// RSA Private File
AppRsaPrivateFile = "rsa/private.pem"
PASSWORD_DEFAULT = 1
)
......@@ -28,6 +28,7 @@ require (
github.com/satori/go.uuid v1.2.0 // indirect
github.com/valyala/fasttemplate v1.1.0 // indirect
github.com/xinliangnote/go-util v0.0.0-20200323134426-527984dc34bf
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
gopkg.in/go-playground/validator.v9 v9.29.1
gopkg.in/ini.v1 v1.51.1 // indirect
......
package encrypt
import (
config "bwallet/conf"
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"golang.org/x/crypto/bcrypt"
)
// 加密 aes_128_cbc
......@@ -55,3 +57,13 @@ func pkcs5UnPadding(decrypted []byte) []byte {
unPadding := int(decrypted[length-1])
return decrypted[:(length - unPadding)]
}
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), config.PASSWORD_DEFAULT)
return string(bytes), err
}
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment