zdpgo_password

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2022 License: MIT Imports: 18 Imported by: 3

README

zdpgo_password

超简单的Golang密码加密便捷工具库

项目地址:https://github.com/zhangdapeng520/zdpgo_password

基本使用

快速入门
package main

import (
	"fmt"
	"github.com/zhangdapeng520/zdpgo_password"
)

func main() {
	passwordConfig := zdpgo_password.ZdpPasswordConfig{
		Debug: true,
	}
	p := zdpgo_password.New(passwordConfig)

	// 默认密码加密方式
	result := p.Make("123456")
	fmt.Println(result)
	// 检查
	fmt.Println(p.Check("123456", result))

	// md5密码加密方式
	result = p.Md5("123456")
	fmt.Println(result)
	// 校验
	fmt.Println(p.Md5Check("123456", result))
}

版本历史

  • 2022年1月16日 版本0.1.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPassword

func CheckPassword(rawPwd, encodedPwd string) bool

CheckPassword 默认的密码校验方式 @param rawPwd 原始密码 @param encodedPwd 加密后的密码

func Encode

func Encode(rawPwd string, options *Options) (string, string)

Encode 对密码按照指定配置进行加密。如果参数2是nil,则使用默认的配置。返回加密后的字符串。 @param rawPwd 要加密的密码 @param options 加密配置

func MakePassword

func MakePassword(rawPwd string) string

MakePassword 默认的密码加密方式,返回加密的密码 @param rawPwd 要加密的密码

func SSLCreate

func SSLCreate()

创建SSL证书

func Verify

func Verify(rawPwd string, salt string, encodedPwd string, options *Options) bool

Verify 校验密码 @param rawPwd 原始密码 @param salt 盐值 @param encodedPwd 加密后的密码 @param options 加密配置 @return bool 校验密码是否正确

Types

type Options

type Options struct {
	SaltLen      int              // 盐的长度
	Iterations   int              // 迭代次数
	KeyLen       int              // 键的长度
	HashFunction func() hash.Hash // hash加密函数
}

type ZdpPassword

type ZdpPassword struct {
	// contains filtered or unexported fields
}

密码加密核心对象

func New

func New(config ZdpPasswordConfig) *ZdpPassword

创建加密对象

func (*ZdpPassword) Check

func (p *ZdpPassword) Check(userPassword, dataPassword string) bool

Check 检查密码是否正确 @param userPassword 用户输入的密码 @param dataPassword 数据库中加密的密码

func (*ZdpPassword) Make

func (p *ZdpPassword) Make(password string) string

Make 密码加密 @param password 用户要加密的密码

func (*ZdpPassword) Md5

func (p *ZdpPassword) Md5(content string) string

Md5 生成md5加密字符串 @param content 要加密的内容

func (*ZdpPassword) Md5Check

func (p *ZdpPassword) Md5Check(content string, md5Content string) bool

Md5Check 生成md5加密字符串 @param content 要加密的内容 @param md5Content md5加密后的内容

type ZdpPasswordConfig

type ZdpPasswordConfig struct {
	Debug       bool   // 是否为debug模式
	LogFilePath string // 日志路径
}

配置对象

Directories

Path Synopsis
examples
sslcreate command
z01_hello command
plugins
pbkdf2
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL