Documentation ¶
Overview ¶
Package passwd contains methods for working with passwords
Index ¶
- Variables
- func Check(password, pepper, hash string) bool
- func CheckBytes(password, pepper, hash []byte) bool
- func GenPassword(length int, strength Strength) string
- func GenPasswordBytes(length int, strength Strength) []byte
- func GenPasswordBytesVariations(password []byte) [][]byte
- func GenPasswordVariations(password string) []string
- func Hash(password, pepper string) (string, error)
- func HashBytes(password, pepper []byte) ([]byte, error)
- type Strength
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func Check ¶
Check compares password with encrypted hash
Example ¶
password, pepper := "MyPassword", "ABCD1234abcd1234" hash, err := Hash(password, pepper) if err != nil { panic(err.Error()) } fmt.Printf("Valid: %t\n", Check(password, pepper, hash))
Output: Valid: true
func CheckBytes ¶
CheckBytes compares password with encrypted hash
Example ¶
password, pepper := []byte("MyPassword"), []byte("ABCD1234abcd1234") hash, err := HashBytes(password, pepper) if err != nil { panic(err.Error()) } fmt.Printf("Valid: %t\n", CheckBytes(password, pepper, hash))
Output: Valid: true
func GenPassword ¶
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 GenPasswordBytes ¶
GenPassword generates random password
Example ¶
weakPassword := GenPasswordBytes(16, STRENGTH_WEAK) medPassword := GenPasswordBytes(16, STRENGTH_MEDIUM) strongPassword := GenPasswordBytes(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 GenPasswordBytesVariations ¶
GenPasswordBytesVariations generates password variants with possible typos fixes (case swap for all letters, first leter swap, password without last symbol)
Example ¶
password := []byte("myPassword12345") variants := GenPasswordBytesVariations(password) fmt.Printf("Variants: %v\n", variants)
Output: Variants: [[77 89 112 65 83 83 87 79 82 68 49 50 51 52 53] [77 121 80 97 115 115 119 111 114 100 49 50 51 52 53] [109 121 80 97 115 115 119 111 114 100 49 50 51 52]]
func GenPasswordVariations ¶
GenPasswordVariations generates password variants with possible typos fixes (case swap for all letters, first leter swap, password without last symbol)
Example ¶
password := "myPassword12345" variants := GenPasswordVariations(password) fmt.Printf("Variants: %v\n", variants)
Output: Variants: [MYpASSWORD12345 MyPassword12345 myPassword1234]
func Hash ¶
Hash creates hash and encrypts it with salt and pepper
Example ¶
password, pepper := "MyPassword", "ABCD1234abcd1234" hash, err := Hash(password, pepper) if err != nil { panic(err.Error()) } fmt.Printf("Hash: %s\n", hash)
Output:
Types ¶
type Strength ¶
type Strength uint8
func GetPasswordBytesStrength ¶
GetPasswordBytesStrength returns password strength
Example ¶
strength := GetPasswordBytesStrength([]byte("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
func GetPasswordStrength ¶
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