lundi 23 mai 2016

If statement is not executing as expected in Sinatra

I'm currently working on a very basic login system, for a Web development school project. My Problem is, that although both variables have the same values and most likely the same data-type as well, the if block does not execute the code for the "true" condition. I already tried to convert both variables into a string(.to_s), but that didn't helped me at all.

Here is the code:

pass = use_database "EMTippspiel", :return_format => "string" do |db|
    sql = "SELECT Passwort FROM user WHERE Benutzername = '" + username + "';"
    db.execute sql
end

if params[:password].to_s == pass
    use_database "EMTippspiel" do |db|
        sql = "UPDATE user SET Online = 'true', IP = '" + ip + "' WHERE Benutzername = '" + username + "';" 
        db.execute sql
    end
    redirect to("/hauptseite")
else
    puts "="*80            #for debugging
    puts username
    puts params[:password] 
    puts pass  
    puts "="*80
    @success = false
    redirect to("/anmeldung")
end

The console window prints out the right values, i.e:

======================================================
Jemin
1965
1965
======================================================

I have no idea whatsoever. What the heck did i wrong?

Aucun commentaire:

Enregistrer un commentaire