48 lines
877 B
Go
48 lines
877 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"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()
|
|
config = ReadConfigFile(configFile)
|
|
|
|
db, err = sql.Open("postgres", config.Database)
|
|
if err != nil {
|
|
os.Exit(111)
|
|
}
|
|
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)
|
|
}
|
|
|
|
output, _ := libpassword.Validate(realPassword, password)
|
|
if output {
|
|
os.Exit(0)
|
|
} else {
|
|
os.Exit(1)
|
|
}
|
|
}
|