mirror of
https://github.com/ergochat/ergo.git
synced 2026-01-10 04:12:06 -08:00
move password handling into a single file
This commit is contained in:
parent
b421971b61
commit
9aa7debbfe
4 changed files with 45 additions and 20 deletions
|
|
@ -1,24 +1,12 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"code.google.com/p/go.crypto/bcrypt"
|
||||
"encoding/base64"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/jlatt/ergonomadic/irc"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func genPasswd(passwd string) {
|
||||
crypted, err := bcrypt.GenerateFromPassword([]byte(passwd), bcrypt.MinCost)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
encoded := base64.StdEncoding.EncodeToString(crypted)
|
||||
fmt.Println(encoded)
|
||||
}
|
||||
|
||||
func main() {
|
||||
conf := flag.String("conf", "ergonomadic.json", "ergonomadic config file")
|
||||
initdb := flag.Bool("initdb", false, "initialize database")
|
||||
|
|
@ -26,7 +14,11 @@ func main() {
|
|||
flag.Parse()
|
||||
|
||||
if *passwd != "" {
|
||||
genPasswd(*passwd)
|
||||
encoded, err := irc.GenerateEncodedPassword(*passwd)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Println(encoded)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -37,6 +29,7 @@ func main() {
|
|||
|
||||
if *initdb {
|
||||
irc.InitDB(config.Database())
|
||||
log.Println("database initialized: " + config.Database())
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue