Click here to Skip to main content
15,894,720 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi,
I am new for asp.net mvc 5, I need to create a admin login page here username and password should take from database what I have given in DB. for example

SQL
id	username	password
1001	admin	        admin


So, here When I entered username is "admin" and password is"admin" it should navigate to next page.

Please provide the step by step process to complete this task .. Thank you in advance ..
Posted
Updated 9-Aug-16 4:35am
v2
Comments
F-ES Sitecore 3-Mar-16 7:44am    
For step by step instructions google for tutorials on building an authentication system, or just use ASP.NET Membership or Identity which give you this functionality out of the box.
Member 12224368 5-Mar-16 4:14am    
Thank You Very much...
I have followed same. but I am getting "Error 1 The name 'context' does not exist in the current context". at RoleController, below is my code
public ActionResult Index()
{
if (User.Identity.IsAuthenticated)
{
if (!isAdminUser())
{
return RedirectToAction("Index", "Home");
}
}
else
{
return RedirectToAction("Index", "Home");
}
var Roles = context.Roles.ToList(); // Here I am getting error on context
return View(Roles);
}

private bool isAdminUser()
{
throw new NotImplementedException();
}

......

Please any body help me to resolve this error.

Thank you ..

1 solution

Simple do this:
C#
if(username == "Admin" && password == "Admin") {
   Response.Redirect("~/new/page");
}

But do you really want to do that? No! That's exactly why there are authentication systems provided. In ASP.NET, you are provided with Identity system that can be used to provide a great and secure authentication system.

I don't find any reason to develop an authentication system from scratch. Also, if you really want to, please hash the password before saving. It is not good at all, the way it is. Any potential user can read the file and know what password Admin has.

Also, since Identity supports Roles. You would create users in Admin role and change the UI for the application for them. Otherwise, provide a basic one. I don't want to help you build a new one, instead, just learn how to do that in ASP.NET and allow it to maintain the authentication for you; they have a great authentication service and have tested in many cases.

ASP.NET Identity | The ASP.NET Site[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900