diff options
author | Julien Dessaux | 2021-04-12 12:44:42 +0200 |
---|---|---|
committer | Julien Dessaux | 2021-04-12 12:44:42 +0200 |
commit | ce5111b4eba9c93dc155f0e5a0f02351a518eb16 (patch) | |
tree | 32518f2cc42f9607f0a782abba7c56d52a5bb639 /pkg/database | |
parent | Implemented the user login database function (diff) | |
download | trains-ce5111b4eba9c93dc155f0e5a0f02351a518eb16.tar.gz trains-ce5111b4eba9c93dc155f0e5a0f02351a518eb16.tar.bz2 trains-ce5111b4eba9c93dc155f0e5a0f02351a518eb16.zip |
Renamed password column to hash in database
Diffstat (limited to '')
-rw-r--r-- | pkg/database/migrations.go | 2 | ||||
-rw-r--r-- | pkg/database/users.go | 4 |
2 files changed, 3 insertions, 3 deletions
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( |