Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
H I am making an ASP.NET Web Forms app and i'm searching for way to do a good, secured and easy to make Login Page .
My main problem that i already have a SQL DataBase and i'm using EF + LINQ to operate with this . Because of that i can't use Idenity, Owin and Katana ( if some one now how it can be make in VS 2012 it will helps me too ) .
Please help me to choose technology for make Login Page or some samples using EF +LINQ +WEB Forms .

What I have tried:

Make it throw : Owin, Idenity and Sql Membership . First is bad because i need migration for this , second because i need to use Linq
Posted
Updated 17-Aug-16 7:29am
Comments
F-ES Sitecore 11-Aug-16 9:35am    
Using EF doesn't stop you using Identity or Membership. If you're worried about database stability then keep your Identity records in its own database so you don't need to worry about migration or changes to your other database.

The first rule of security is that you never roll your own.
Андрей Голубцов 11-Aug-16 10:53am    
You don't understand my question . I can't make it with Idenity because it need to create new tables (it generates when you use it), i can't use Membership, because i use Linq and EF . Because of that i asking how to make good login page with ef +linq +web forms
F-ES Sitecore 11-Aug-16 10:56am    
Both of those technologies are completely self-contained and have nothing to do with what you use to access your own data. If you couldn't use Membership or Identity because you're using EF then no-one would be using Identity or Membership, they'd be useless and you'd have found a thousand tutorials on how to do your own login as everyone would be doing it.
Андрей Голубцов 11-Aug-16 11:15am    
I tried to use tutorials but they all are about idenity or not about EF or not linq.
Vincent Maverick Durano 17-Aug-16 13:36pm    
F-ES Sitecore is correct. Using EF and LINQ has nothing to do wether you use Indenty or Membership providers. For clarifications, you may need to read the docs about each of them.

1 solution

Using EF and LINQ has nothing to do with using Identity or SQL Membership. EF is an object relational mapper (ORM) and you'll use it as a replacement for good-old-plain ADO.NET to work with data. LINQ on the other hand is used for querying objects and collections. For example objects generated from your EF. LINQ also provides a handfull of extension methods that you can use to easily manipulate the objects/collections when querying. Having that said, you could still use LINQ and EF to work with ASP.NET Identity.

But if you don't want to use Indentity or Membership then you could something like this:

C#
private string GetUserPassword(string loginName) {  
            using (DBEntities db = new DBEntities()) {  
                var user = db.SYSUsers.Where(o => o.LoginName.ToLower().Equals(loginName));  
                if (user.Any())  
                    return user.FirstOrDefault().PasswordEncryptedText;  
                else  
                    return string.Empty;  
            }  
} 

protected void Button1_Click(object sender, EventArgs e){  
		string loginName = txtLoginName.Text.Trim();
        	string password = GetUserPassword(loginName);  
  
                if (string.IsNullOrEmpty(password))  
                    Response.Write("The user login or password provided is incorrect.");  
                else {  
                    if (txtPassword.Text.Equals(password)) {  
                        FormsAuthentication.SetAuthCookie(loginName, false);  
                        Response.Redirect("~/Home.aspx");
   
                        //you can also use the FormsAuthentication.RedirectFromLoginPage() 
                        //to redirect 
                    }  
                    else {  
                        Response.Write("The password provided is incorrect.");  
                    }  
                } 
} 


Note that the code above is just a simple snippet describing the use of EF and LINQ to authenticate users in WebForms. You may need to change some of the code based on your database and controls.
 
Share this answer
 
v2

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