require 'sqlite3' require 'json' require 'securerandom' require 'scrypt' require_relative 'collab.rb' $db = SQLite3::Database.new "data/test.db" def get_user(id) puts $db.execute("SELECT * FROM Users WHERE name = ?", [id]) end def add_user(user) $db.execute("INSERT INTO Users (name) VALUES (?)", [user.id]) end def update_user(user) $db.execute("UPDATE Users SET keys = ? WHERE name = ?", [JSON.generate(user.keys),user.id]) end def change_user_password(user,password) salt = SecureRandom.base64(32) hash = SCrypt::Password.create(salt + password) $db.execute("UPDATE Users SET passwd = ?, salt = ? WHERE name = ?", [hash,salt,user.id]) end #user1 = User.new("user1") #add_user(user1) #change_user_password(user1,"testtest")