GoPasswordUtilities

package module
v0.0.0-...-2e33067 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2016 License: Apache-2.0 Imports: 11 Imported by: 0

README

GoPasswordUtilities

GoDoc Build Status

Simple library for working with passwords in Go (Golang).

Complexity check will check for upper case letters, lower case letters, numbers, special characters and also whether the password is dictionary based.

For more detail about the library and its features, reference your local godoc once installed.

godoc -http=:6060

Features

  • Generate a Password
  • Run a Complexity Check
  • Hash a Password
  • Salt a Password

Warning

This library is in alpha and will be subject to change. Use with caution. There's also a damn good chance it could be in a broken state at times as well.

Installation

go get github.com/briandowns/GoPasswordUtilities

Examples

Import the package, generate a password and hash it.
package main

import (
	"fmt"
	gpu "github.com/briandowns/GoPasswordUtilities"
)

func main() {
	p := gpu.GeneratePassword(10)
	fmt.Println(p)
	fmt.Printf("%x\n", p.MD5())
}
Create a new password object and get its information
    pass := gpu.New("secret12")
    fmt.Println(*pass)
    
    results, err := gpu.ProcessPassword(pass)
    if err != nil {
        fmt.Println(err)
    }
    fmt.Printf("Has Rating: %s\n", results.ComplexityRating())
    fmt.Printf("%t\n", results.DictionaryBased)
Generate thousands of passwords.
    // On the fly compile and execution.  Better 
    ///once statically compiled.
    // 0.19s user 0.07s system 84% cpu 0.303 total
    passChan := make(chan *gpu.Password, 10000)
    go func() {
        for i := 0; i < 10000; i++ {
            passChan <- gpu.GeneratePassword(8)
        }
        close(passChan)
    }()

    for pass := range passChan {
        fmt.Printf("%s\n", pass.Pass)
    }
Generate a Very Strong password.
    p := gpu.GenerateVeryStrongPassword(10)
    fmt.Println(p.Pass)
Hash a password that includes a generated salt.
    p := gpu.GeneratePassword(10)
    fmt.Println(p.Pass)
    hash1, _ := p.SHA256()
    hash2, salt := p.SHA256(&gpu.SaltConf{Length: 32})
    fmt.Printf("%x\n", hash1)
    fmt.Printf("%x - %x\n", hash2, salt)   

Documentation

Overview

Simple library for working with passwords in Go. All generated passwords are going to be a minimum of 8 characters in length.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Password

type Password struct {
	Pass            string
	Length          int
	Score           int
	ContainsUpper   bool
	ContainsLower   bool
	ContainsNumber  bool
	ContainsSpecial bool
	DictionaryBased bool
}

func GeneratePassword

func GeneratePassword(length int) *Password

GeneratePassword will generate and return a password as a string and as a byte slice of the given length.

func GenerateVeryStrongPassword

func GenerateVeryStrongPassword(length int) *Password

GenerateVeryStrongPassword will generate a "Very Strong" password.

func New

func New(password string) *Password

New is used when a user enters a password as well as the being called from the GeneratePassword function.

func (*Password) ComplexityRating

func (p *Password) ComplexityRating() string

ComplexityRating provides the rating for the password.

func (*Password) GetLength

func (p *Password) GetLength() int

GetLength will provide the length of the password. This method is being put on the password struct in case someone decides not to do a complexity check.

func (*Password) GetScore

func (p *Password) GetScore() int

GetScore will provide the score of the password.

func (*Password) HasLower

func (p *Password) HasLower() bool

HasLower indicates whether the password contains a lower case letter.

func (*Password) HasNumber

func (p *Password) HasNumber() bool

HasNumber indicates whether the password contains a number.

func (*Password) HasSpecial

func (p *Password) HasSpecial() bool

HasSpecial indicates whether the password contains a special character.

func (*Password) HasUpper

func (p *Password) HasUpper() bool

HasUpper indicates whether the password contains an upper case letter.

func (*Password) InDictionary

func (p *Password) InDictionary() bool

InDictionary will return true or false if it's been detected that the given password is a dictionary based.

func (*Password) MD5

func (p *Password) MD5(saltConf ...*SaltConf) ([16]byte, []byte)

MD5 sum for the given password. If a SaltConf pointer is given as a parameter a salt with the given length will be returned with it included in the hash.

func (*Password) ProcessPassword

func (p *Password) ProcessPassword()

ProcessPassword will parse the password and populate the Password struct attributes.

func (*Password) SHA256

func (p *Password) SHA256(saltConf ...*SaltConf) ([32]byte, []byte)

SHA256 sum for the given password. If a SaltConf pointer is given as a parameter a salt with the given length will be returned with it included in the hash.

func (*Password) SHA512

func (p *Password) SHA512(saltConf ...*SaltConf) ([64]byte, []byte)

SHA512 sum for the given password. If a SaltConf pointer is given as a parameter a salt with the given length will be returned with it included in the hash.

type SaltConf

type SaltConf struct {
	Length int
}

Jump to

Keyboard shortcuts

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