From ce5111b4eba9c93dc155f0e5a0f02351a518eb16 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Mon, 12 Apr 2021 12:44:42 +0200 Subject: Renamed password column to hash in database --- pkg/database/migrations.go | 2 +- pkg/database/users.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'pkg/database') diff --git a/pkg/database/migrations.go b/pkg/database/migrations.go index 8d23ed2..8cc6420 100644 --- a/pkg/database/migrations.go +++ b/pkg/database/migrations.go @@ -13,7 +13,7 @@ var allMigrations = []func(tx *sql.Tx) error{ CREATE TABLE users ( id INTEGER PRIMARY KEY, username TEXT NOT NULL UNIQUE, - password TEXT, + hash TEXT, email TEXT, created_at DATE DEFAULT (datetime('now')), last_login_at DATE DEFAULT NULL diff --git a/pkg/database/users.go b/pkg/database/users.go index 10e6416..c7e67e3 100644 --- a/pkg/database/users.go +++ b/pkg/database/users.go @@ -13,7 +13,7 @@ func (env *DBEnv) CreateUser(reg *model.UserRegistration) (*model.User, error) { } query := ` INSERT INTO users - (username, password, email) + (username, hash, email) VALUES ($1, $2, $3);` tx, err := env.db.Begin() @@ -50,7 +50,7 @@ func (env *DBEnv) CreateUser(reg *model.UserRegistration) (*model.User, error) { // a PasswordError is return if the passwords do not match // a QueryError is returned if the username contains invalid sql characters like % func (env *DBEnv) Login(login *model.UserLogin) (*model.User, error) { - query := `SELECT id, password, email FROM users WHERE username = $1;` + query := `SELECT id, hash, email FROM users WHERE username = $1;` user := model.User{Username: login.Username} var hash string err := env.db.QueryRow( -- cgit v1.2.3