mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 05:08:14 +03:00
parent
c210b50433
commit
93b627ceab
20
main.go
20
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"crypto"
|
"crypto"
|
||||||
@ -1777,11 +1778,20 @@ pick a random, unguessable password, preferably at least 12 characters.
|
|||||||
|
|
||||||
`)
|
`)
|
||||||
fmt.Printf("password: ")
|
fmt.Printf("password: ")
|
||||||
buf := make([]byte, 64)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
n, err := os.Stdin.Read(buf)
|
// The default splitter for scanners is one that splits by lines, so we
|
||||||
xcheckf(err, "reading stdin")
|
// don't have to set up another one here.
|
||||||
pw := string(buf[:n])
|
|
||||||
pw = strings.TrimSuffix(strings.TrimSuffix(pw, "\r\n"), "\n")
|
// We discard the return value of Scan() since failing to tokenize could
|
||||||
|
// either mean reaching EOF but no newline (which can be legitimate if the
|
||||||
|
// CLI was programatically called to set the password, but with no trailing
|
||||||
|
// newline), or an actual error. We can distinguish between the two by
|
||||||
|
// calling Err() since it will return nil if it were EOF, but the actual
|
||||||
|
// error if not.
|
||||||
|
scanner.Scan()
|
||||||
|
xcheckf(scanner.Err(), "reading stdin")
|
||||||
|
// No need to trim, the scanner does not return the token in the output.
|
||||||
|
pw := scanner.Text()
|
||||||
if len(pw) < 8 {
|
if len(pw) < 8 {
|
||||||
log.Fatal("password must be at least 8 characters")
|
log.Fatal("password must be at least 8 characters")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user