sum7/warehost
sum7
/
warehost
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
warehost/cmd/warehost-auth/main.go

48 lines
877 B
Go
Raw Normal View History

2016-11-24 23:58:03 +01:00
package main
import (
"flag"
2016-11-24 23:58:03 +01:00
"os"
"database/sql"
_ "github.com/lib/pq"
libpassword "dev.sum7.eu/sum7/warehost/lib/password"
)
var (
configFile string
username string
password string
config *Config
db *sql.DB
err error
)
func main() {
flag.StringVar(&configFile, "c", "config.yml", "path of configuration file")
flag.StringVar(&username, "u", "none", "username")
flag.StringVar(&password, "p", "none", "password")
flag.Parse()
2016-11-24 23:58:03 +01:00
config = ReadConfigFile(configFile)
db, err = sql.Open("postgres", config.Database)
if err != nil {
os.Exit(111)
2016-11-24 23:58:03 +01:00
}
defer db.Close()
var realPassword string
err = db.QueryRow("select password from login where mail = $1", username).Scan(&realPassword)
if err != nil {
os.Exit(3)
2016-11-24 23:58:03 +01:00
}
output, _ := libpassword.Validate(realPassword, password)
if output {
os.Exit(0)
2016-11-24 23:58:03 +01:00
} else {
os.Exit(1)
}
}