Reputation: 23
I am trying to make a simple command line user authentication system in Ruby.
I am using MySQL to store user information.
I decided to store the passwords as MD5 hashes, mainly because it is simple.
I am not going for anything crazy secure at the moment, I just want it to work.
However when I use a select statement in Ruby to pull the hash out so I can compare it with a hash of whatever the user entered it does not come out in the same 32 character format!
When I use MySQL to select the hash I get:
SELECT password FROM users WHERE username = 'admin';
+----------------------------------+
| password |
+----------------------------------+
| d456c1f6fa85ed2f6a26b15139c6ddc2 |
+----------------------------------+
When I use Ruby however..
con.query("SELECT password FROM users WHERE username = 'admin'")
#<Mysql::Result:0x950b208>
I haven't ever really programmed anything before, and am really enjoying Ruby.
I have been googling this for two days now and can't seem to find anything.
I am sorry if this is a really easy fix, but I cant seem to find it anywhere.
I would also love suggestions about a better way to go about this little project! Thanks in advance :)
Upvotes: 2
Views: 2104
Reputation: 41242
It looks like you need to just process the results of the query. The return value of query
is a result set object:
rows = con.query("SELECT password FROM employee WHERE username = 'admin'")
rows.each do |row|
puts row[0]
end
Upvotes: 4