rndpass

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2023 License: MIT Imports: 7 Imported by: 0

README

GoDoc

rndpass

Simple package to generate random passwords and similar. This comes in handy surprisingly often and having a good version (using secure random generator) of this can be very helpful.

Sample use

password := rndpass.MustSecureCode(32, rndpass.RangePassword, nil)

Documentation

Index

Constants

View Source
const (
	RangeFull       = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
	RangePassword   = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789&~#([-|_^@)]{}$*,?;.:/!<>"
	RangeAlnumLower = "abcdefghijklmnopqrstuvwxyz0123456789"
	RangeNumeric    = "0123456789"
)

Variables

This section is empty.

Functions

func Code

func Code(ln int, set string) string

Code generates a random string made of ln characters taken from set. For example to generate a random password of 32 characters, you can simply call Code(32, rndpass.RangePassword). This method uses golang's math/rand random generator and is not considered secure, but can come in handy in some cases as it cannot fail.

If you need higher quality randomness, please use SecureCode()

func MustSecureCode

func MustSecureCode(ln int, set string, rnd io.Reader) string

MustSecureCode will generate a code similar to SecureCode, and will panic should the random generator fail to generate randomness (which is the proper action to take in this case).

func SecureCode

func SecureCode(ln int, set string, rnd io.Reader) (string, error)

SecureCode method works similarly to Code() except it uses a secure random source (if rnd is nil, crypto/rand.Reader is used by default) and may return an error if reading from the random source fails (it shouldn't). This method will be slower than Code() but comes with a much higher randomness quality.

Types

This section is empty.

Jump to

Keyboard shortcuts

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