Reputation: 15
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
Reputation: 974
Ok, so this is a three step process
Tip: donot go near the database if the username or password is null, otherwise you are exposing your database to hackers.
Upvotes: 1
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