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.
2016-11-24 23:58:03 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-11-27 10:46:50 +01:00
|
|
|
"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() {
|
2016-11-27 10:46:50 +01:00
|
|
|
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 {
|
2016-11-27 10:46:50 +01:00
|
|
|
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 {
|
2016-11-27 10:46:50 +01:00
|
|
|
os.Exit(3)
|
2016-11-24 23:58:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
output, _ := libpassword.Validate(realPassword, password)
|
|
|
|
if output {
|
2016-11-27 10:46:50 +01:00
|
|
|
os.Exit(0)
|
2016-11-24 23:58:03 +01:00
|
|
|
} else {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|