passwd

package
v12.20.2+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package passwd contains methods for working with passwords

Index

Examples

Constants

View Source
const (
	STRENGTH_WEAK   = iota // Only lowercase English alphabet characters
	STRENGTH_MEDIUM        // Lowercase and uppercase English alphabet characters, digits
	STRENGTH_STRONG        // Lowercase and uppercase English alphabet characters, digits, special symbols
)

Variables

This section is empty.

Functions

func Check

func Check(password, pepper, hash string) bool

Check compares password and encrypted hash

func Encrypt

func Encrypt(password, pepper string) (string, error)

Encrypt creates hash and encrypts password with salt and pepper

func GenPassword

func GenPassword(length, strength int) string

GenPassword generates random password

Example
weakPassword := GenPassword(16, STRENGTH_WEAK)
medPassword := GenPassword(16, STRENGTH_MEDIUM)
strongPassword := GenPassword(16, STRENGTH_STRONG)

fmt.Printf("Weak password: %s\n", weakPassword)
fmt.Printf("Medium password: %s\n", medPassword)
fmt.Printf("Strong password: %s\n", strongPassword)
Output:

func GetPasswordStrength

func GetPasswordStrength(password string) int

GetPasswordStrength returns password strength

Example
strength := GetPasswordStrength("secret1234%$")

switch strength {
case STRENGTH_STRONG:
	fmt.Println("Password is strong")
case STRENGTH_MEDIUM:
	fmt.Println("Password is ok")
case STRENGTH_WEAK:
	fmt.Println("Password is weak")
}
Output:

Password is ok

Types

This section is empty.

Jump to

Keyboard shortcuts

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