-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathreusedPassword.go
More file actions
35 lines (28 loc) · 849 Bytes
/
reusedPassword.go
File metadata and controls
35 lines (28 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"strings"
)
// ReusedPassword is a password that is used by more than one user
type ReusedPassword struct {
Hash string `json:"hash,omitempty"`
Count int `json:"count"`
Users []string `json:"users"`
}
// NewReusedPassword creates a new ReusedPassword
func NewReusedPassword(user string, hash string) *ReusedPassword {
pw := ReusedPassword{}
pw.Hash = hash
pw.Count = 1
pw.Users = make([]string, 1)
pw.Users[0] = user
return &pw
}
// Add adds a new user to the reused password
func (reusedpassword *ReusedPassword) Add(user string) {
reusedpassword.Count++
reusedpassword.Users = append(reusedpassword.Users, user)
}
func (reusedpassword *ReusedPassword) String() string {
return fmt.Sprintf("%dx %s (%s)", reusedpassword.Count, reusedpassword.Hash, strings.Join(reusedpassword.Users, ","))
}