[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 537
  • Last Modified:

SQL return true or False

i have a Database with column username and password. user will key in username and password in a textbox.
i need SQL code to check, if username in the Database then return true.  if username not avialable in the database then return false.
0
aarontham
Asked:
aarontham
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I would use a SqlCommand to return a datareader, and if that reader has no record (if !reader.read()), ...
also, do you want to check the password also, or not?

note: usually, the password is hashed/encrypted in the db, and you have to compare with the hashed/crypted value of the password from user input...
0
 
oleberCommented:
another way is a

SELECT COUNT(*) FROM my_tab WHERE login=?

if count is 0 then you have no user with that login, bigger then 0 you have an user.
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now