|
|
|
@ -20,15 +20,20 @@ func OpenSQLite(path string) (*SQLite, error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if _, err := db.Exec(`
|
|
|
|
|
create table if not exists users (
|
|
|
|
|
create table if not exists players (
|
|
|
|
|
id integer primary key autoincrement,
|
|
|
|
|
name text unique not null,
|
|
|
|
|
phash text not null,
|
|
|
|
|
psalt text not null
|
|
|
|
|
);`); err != nil {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "failed to create users table: %v\n", err)
|
|
|
|
|
fmt.Fprintf(os.Stderr, "failed to create players table: %v\n", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if _, err := db.Exec(`
|
|
|
|
|
// create table if not exists corpses (
|
|
|
|
|
// id integer primary key autoincrement,
|
|
|
|
|
// player integer fo
|
|
|
|
|
|
|
|
|
|
return &SQLite{db: db}, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -40,7 +45,7 @@ func (db *SQLite) CreateUser(name, pass, salt string) error {
|
|
|
|
|
}
|
|
|
|
|
hash := string(hashBytes)
|
|
|
|
|
if _, err := db.db.Exec(`
|
|
|
|
|
insert into users (name, phash, psalt)
|
|
|
|
|
insert into players (name, phash, psalt)
|
|
|
|
|
values (?, ?, ?);
|
|
|
|
|
`, name, hash, salt); err != nil {
|
|
|
|
|
return fmt.Errorf("unable to insert user: %v", err)
|
|
|
|
@ -50,7 +55,7 @@ func (db *SQLite) CreateUser(name, pass, salt string) error {
|
|
|
|
|
|
|
|
|
|
func (db *SQLite) CheckPassword(name, pass string) error {
|
|
|
|
|
rows, err := db.db.Query(`
|
|
|
|
|
select phash, psalt from users where name = ?;
|
|
|
|
|
select phash, psalt from players where name = ?;
|
|
|
|
|
`, name)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return fmt.Errorf("failed to fetch row for user %s: %v", name, err)
|
|
|
|
@ -86,7 +91,7 @@ func (db *SQLite) SetPassword(name, pass, salt string) error {
|
|
|
|
|
}
|
|
|
|
|
hash := string(hashBytes)
|
|
|
|
|
if _, err := db.db.Exec(`
|
|
|
|
|
update users
|
|
|
|
|
update players
|
|
|
|
|
set phash = ?, psalt = ?
|
|
|
|
|
where name = ?;
|
|
|
|
|
`, hash, salt, name); err != nil {
|
|
|
|
|