Skip to content

Instantly share code, notes, and snippets.

@ieve-rothe
Created July 26, 2012 20:47
Show Gist options
  • Select an option

  • Save ieve-rothe/3184414 to your computer and use it in GitHub Desktop.

Select an option

Save ieve-rothe/3184414 to your computer and use it in GitHub Desktop.
pry output showing sqlite search problem
[3] pry(main)> db.execute "select * from Users"
=> [["sanarothe2",
"f82e77528ed1a1cc7fe33fcf751d90b11cd77d45",
"3eec25493d63be0ad6fc3e196d9b0e472babddb7",
"cccb6c91-c722-44cd-adce-51504e717bdb"],
["sanarothe",
"6dc00946d373b7eeffff8b2a09535bd3105eb201",
"0d01e5810b361c02731a8c178014ccbe86ca6f07",
"b315763b-d234-4e2c-908a-7c403987785d"]]
[4] pry(main)> db.execute "select * from Users where Username=?", 'sanarothe'
=> []
[5] pry(main)> db.execute "select * from Users where Username=?", 'sanarothe2'
=> []
[6] pry(main)> db.execute "select * from Users where Username=?", "sanarothe"
=> []
[7] pry(main)> db.execute "select * from Users where Username=?", "sanarothe"
=> []
def register_user(user_name, user_password, user_password_confirmation)
db = SQLite3::Database.new("users.db")
check_existing_user = db.prepare("SELECT * FROM Users WHERE Username = ?")
user = check_existing_user.execute user_name
user_exists_result = user.next # user.next will return nil if there are no more values to check out
check_existing_user.close
if user_password != user_password_confirmation
return "01:PasswordMismatch"
elsif user_exists_result == nil
salt = generate_salt
hash = generate_hash(user_password, salt)
uuid = generate_uuid
insert_new_user_stmt = db.prepare "INSERT INTO Users VALUES (?, ?, ?, ?)"
puts user_name
puts hash
puts salt
puts uuid
insert_new_user_stmt.execute user_name.chomp, hash, salt, uuid
insert_new_user_stmt.close
puts "01:RegisteredNewUser -- #{user_name}"
return "01:RegisteredNewUser"
else
return "01:FoundUser"
end
db.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment