require 'sqlite3' def create_new_user(username, password) db = SQLite3::Database.new('./database/auth.db') db.execute(' INSERT INTO users (username, hashed_password) VALUES (?, ?) ', [username.downcase, create_password_for_user(password)]) end def check_if_user_exists(username) db = SQLite3::Database.new('./database/auth.db') result = db.get_first_value('SELECT COUNT(*) FROM users WHERE username = ?', username.downcase) if result > 0 return true else return false end end def get_user_id(username) db = SQLite3::Database.new('./database/auth.db') user_id = db.get_first_value(' SELECT id FROM users U WHERE U.username = ? ', [username.downcase]) return user_id end def get_user_hashed_password(user_id) db = SQLite3::Database.new('./database/auth.db') password_hash = db.get_first_value(' SELECT hashed_password FROM users U WHERE U.id = ? ', [user_id]) return password_hash end def update_user_password(user_id, password) db = SQLite3::Database.new('./database/auth.db') db.execute(' UPDATE users SET hashed_password = ?, salt = ? WHERE id = ? ', [hash_password, salt, user_id]) end