Debian Codegraph @

README.md

raw symbols SCIP
1 ## Golang Password Generator
2
3 [![GoDoc](https://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://pkg.go.dev/github.com/sethvargo/go-password/password)
4 [![GitHub Actions](https://img.shields.io/github/workflow/status/sethvargo/go-password/Test?style=flat-square)](https://github.com/sethvargo/go-password/actions?query=workflow%3ATest)
5
6 This library implements generation of random passwords with provided
7 requirements as described by [AgileBits
8 1Password](https://discussions.agilebits.com/discussion/23842/how-random-are-the-generated-passwords)
9 in pure Golang. The algorithm is commonly used when generating website
10 passwords.
11
12 The library uses crypto/rand for added randomness.
13
14 Sample example passwords this library may generate:
15
16 ```text
17 0N[k9PhDqmmfaO`p_XHjVv`HTq|zsH4XiH8umjg9JAGJ#\Qm6lZ,28XF4{X?3sHj
18 7@90|0H7!4p\,c<!32:)0.9N
19 UlYuRtgqyWEivlXnLeBpZvIQ
20 Q795Im1VR5h363s48oZGaLDa
21 wpvbxlsc
22 ```
23
24 > Since these are completely randomized, it's possible that they may generate passwords that don't comply with some custom password policies, such as ones that require both upper case AND lower case letters. If your particular use case needs a mix of casing, then you can either increase the number of characters in the password or check the output and regenerate if it fails a particular constraint, such as requiring both upper and lower case.
25
26 ## Installation
27
28 ```sh
29 $ go get -u github.com/sethvargo/go-password/password
30 ```
31
32 ## Usage
33
34 ```golang
35 package main
36
37 import (
38 "log"
39
40 "github.com/sethvargo/go-password/password"
41 )
42
43 func main() {
44 // Generate a password that is 64 characters long with 10 digits, 10 symbols,
45 // allowing upper and lower case letters, disallowing repeat characters.
46 res, err := password.Generate(64, 10, 10, false, false)
47 if err != nil {
48 log.Fatal(err)
49 }
50 log.Printf(res)
51 }
52 ```
53
54 See the [GoDoc](https://godoc.org/github.com/sethvargo/go-password) for more
55 information.
56
57 ## Testing
58
59 For testing purposes, instead of accepted a `*password.Generator` struct, accept
60 a `password.PasswordGenerator` interface:
61
62 ```go
63 // func MyFunc(p *password.Generator)
64 func MyFunc(p password.PasswordGenerator) {
65 // ...
66 }
67 ```
68
69 Then, in tests, use a mocked password generator with stubbed data:
70
71 ```go
72 func TestMyFunc(t *testing.T) {
73 gen := password.NewMockGenerator("canned-response", false)
74 MyFunc(gen)
75 }
76 ```
77
78 In this example, the mock generator will always return the value
79 "canned-response", regardless of the provided parameters.
80
81 ## License
82
83 This code is licensed under the MIT license.