-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (30 loc) · 867 Bytes
/
main.go
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
36
37
38
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
"golang.org/x/crypto/bcrypt"
)
func main() {
file, err := os.OpenFile("../.credentials", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Fatal("failed to open file", err)
}
defer file.Close()
var username string
var password string
flag.StringVar(&username, "u", "", "username")
flag.StringVar(&password, "p", "", "password")
flag.Parse()
if len(username) < 1 || len(password) < 1 {
log.Fatal("no username or password provided")
}
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), 8)
user := strings.ToLower(username)
if _, err := file.WriteString(fmt.Sprintf("%s:%s\n", user, string(hashedPassword))); err != nil {
log.Fatal("failed to write credentials to file", err)
}
log.Printf("successful stored credentials for user: %s", username)
}