mirror of
https://github.com/chylex/SMTP-Relay.git
synced 2025-04-09 08:15:44 +02:00
Change hasher utility to accept passwords from stdin
This commit is contained in:
parent
7a6128c724
commit
a4a97716e2
@ -2,5 +2,5 @@
|
||||
To run the hasher, do like this
|
||||
|
||||
```bash
|
||||
$ go run hasher.go hunter2
|
||||
$ go run hasher.go
|
||||
```
|
||||
|
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
@ -8,15 +9,28 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Fprintln(os.Stderr, "Usage: hasher PASSWORD")
|
||||
os.Exit(1)
|
||||
}
|
||||
password := os.Args[1]
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
|
||||
for scanner.Scan() {
|
||||
password := scanner.Text()
|
||||
if len(password) == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
hash, err := hash(password)
|
||||
if err != nil {
|
||||
fmt.Printf("Error generating hash: %s\n", err)
|
||||
} else {
|
||||
fmt.Printf("%s: %s\n", password, hash)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hash(password string) (string, error) {
|
||||
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Error generating hash: %s", err)
|
||||
return "", err
|
||||
} else {
|
||||
return string(hash), nil
|
||||
}
|
||||
fmt.Println(string(hash))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user