Fares Joseph Eid
Fares Joseph Eid

Reputation: 15

How to control a log in

So I created a custom generated file that lets me take the username and password.
It is the following:

public User GetUserByUserNamePassword(string userName, string Password)
{
   return (_DatabaseContext.Users.FirstOrDefault(user => user.Username == userName && user.Password ==Password));
}

In my login page I have a webUserControl that contains two textboxes, one for the password and the other one for the username. I created an object data source for the webusercontrol to take in parameters Username and password .

What's the c# code that can let me check if the username and password are valid (I have a table called User btw that has three columns, UserID(pk), Username and Password.

Any help would be greatly appreciated.

Upvotes: 0

Views: 75

Answers (2)

azmuhak
azmuhak

Reputation: 974

Ok, so this is a three step process

  1. You have to check whether the username and password submitted is not null
  2. You have to use a foreach loop for the whole database and match the user id with the user id submitted by the user, same goes with the password
  3. You have to notify the user about success or failure.

Tip: donot go near the database if the username or password is null, otherwise you are exposing your database to hackers.

Upvotes: 1

Emil
Emil

Reputation: 1394

It depends on what you consider as a valid username/password. You can use regex to check if it follows the right pattern before you return the User from the database. This is a good tutorial for Learning regex: http://www.codeproject.com/Articles/9099/The-30-Minute-Regex-Tutorial

Upvotes: 0

Related Questions