SQL script on server side to select row with given credentials

Viewed 33

If I have a sql database with a table called users, how do I go about accessing a row by giving credentials?

There are three columns: username, password, and age. I don't want age to be accessible to everyone. I know how to search a row by using username, but the database should also require you to enter a password that matches the user. I know that this can easily be done on the client side, but clients can be modified and it becomes useless. If it matters, I'm using c++ for the client.

Here's an example of the table

| username | password | age |
―――――――――――――――――――――――――――――
|  johnny  | Abcd123! | 031 |
―――――――――――――――――――――――――――――
|  thomas  | Xyz1234! | 076 |

I need a script or something on the server side, that will only allow me to search a row by entering both the username and password correctly.

Thanks.

1 Answers

Try this

     Select * from table where username = &username
     and password = &password

Eg something like below

   cin >> username
   cin >> password
    Resultset="Select * from table where username =" 
     +username+ "and password =" +password
Related