3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-11-14 07:59:31 +01:00

add ergo checkpasswd to check user passwords

This commit is contained in:
Shivaram Lingamneni 2022-02-19 22:03:30 -05:00
parent 1e7775f6de
commit ccb0206dcc

22
ergo.go
View File

@ -7,6 +7,7 @@ package main
import (
"bufio"
"encoding/json"
"fmt"
"log"
"os"
@ -20,6 +21,7 @@ import (
"github.com/ergochat/ergo/irc"
"github.com/ergochat/ergo/irc/logger"
"github.com/ergochat/ergo/irc/mkcerts"
"github.com/ergochat/ergo/irc/passwd"
)
// set via linker flags, either by make or by goreleaser:
@ -91,6 +93,23 @@ func doMkcerts(configFile string, quiet bool) {
}
}
func doCheckPasswd() (returnCode int) {
reader := bufio.NewReader(os.Stdin)
text, err := reader.ReadBytes('\n')
if err != nil {
log.Fatal(err)
}
var hashAndPassword [2]string
err = json.Unmarshal(text, &hashAndPassword)
if err != nil {
log.Fatal(err)
}
if passwd.CompareHashAndPassword([]byte(hashAndPassword[0]), []byte(hashAndPassword[1])) != nil {
return 1
}
return 0
}
func main() {
irc.SetVersionString(version, commit)
usage := `ergo.
@ -100,6 +119,7 @@ Usage:
ergo importdb <database.json> [--conf <filename>] [--quiet]
ergo genpasswd [--conf <filename>] [--quiet]
ergo mkcerts [--conf <filename>] [--quiet]
ergo checkpasswd
ergo run [--conf <filename>] [--quiet] [--smoke]
ergo -h | --help
ergo --version
@ -144,6 +164,8 @@ Options:
} else if arguments["mkcerts"].(bool) {
doMkcerts(arguments["--conf"].(string), arguments["--quiet"].(bool))
return
} else if arguments["checkpasswd"].(bool) {
os.Exit(doCheckPasswd())
}
configfile := arguments["--conf"].(string)