You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.4 KiB
64 lines
1.4 KiB
package main |
|
|
|
import ( |
|
"bufio" |
|
"fmt" |
|
"os" |
|
"os/exec" |
|
"strings" |
|
|
|
"golang.org/x/crypto/sha3" |
|
"gopkg.in/redis.v5" |
|
) |
|
|
|
func printChangePasswordScreen(redisClient *redis.Client, username string) { |
|
clearScreen() |
|
fmt.Printf(" %s\n", config.NethackLauncher.ServerDisplay) |
|
println("") |
|
fmt.Printf(" Welcome %s\n", username) |
|
println("") |
|
|
|
scanner := bufio.NewScanner(os.Stdin) |
|
|
|
// turn off echo display |
|
exec.Command("stty", "-F", "/dev/tty", "-echo").Run() |
|
reader := bufio.NewReader(os.Stdin) |
|
|
|
noPass := true |
|
sec := "" |
|
for noPass { |
|
// pull pass the first time |
|
fmt.Printf(" Please enter your password (blank entry aborts).\n>> ") |
|
sec0, _ := reader.ReadString('\n') |
|
sec0 = strings.Replace(sec0, "\n", "", -1) |
|
if sec0 == "" { |
|
printWelcomeScreen(redisClient) |
|
} |
|
|
|
// pull pass the second time |
|
fmt.Printf("\n Please enter your password again.\n>> ") |
|
sec1, _ := reader.ReadString('\n') |
|
sec1 = strings.Replace(sec1, "\n", "", -1) |
|
|
|
// make sure passwords match |
|
if sec0 == sec1 { |
|
sec = sec0 |
|
noPass = false |
|
} else { |
|
fmt.Println("Lets try that again.") |
|
} |
|
} |
|
|
|
// reset display |
|
exec.Command("stty", "-F", "/dev/tty", "echo", "-cbreak").Run() |
|
|
|
// set user in redis |
|
secHash := sha3.Sum512([]byte(sec)) |
|
redisClient.Set(fmt.Sprintf("user:%s", username), fmt.Sprintf("%x", secHash), 0).Err() |
|
|
|
// back to main screen |
|
printUserScreen(redisClient, username) |
|
if err := scanner.Err(); err != nil { |
|
fmt.Printf("%s\n", err) |
|
} |
|
}
|
|
|