Fixed database issues

Database connection was opened and immediatly closed -> Fixed
Query for isValidLogin method wasn't working -> Fixed