Quantcast
Channel: CodeProject Latest postings for ASP.NET
Viewing all articles
Browse latest Browse all 3938

How to pass user details from the database - basic auth

$
0
0
Dear all,
 
I am writing to seek help in how do construct function/method which can pass username and password from database in the "userPro" class:
publicclass UserPro : IProvidePrincipal
    {
 
       // private const string Username = "hi";
//private const string Password = "hi";
public IPrincipal CreatePrincipal(string username, string password)
        {
            if (username != Username || password != Password)
            {
                returnnull;
            }
 
            var identity = new GenericIdentity(Username);
 
            IPrincipal principal = new GenericPrincipal(identity, new[] { "admin" });
            return principal;
        } 
 
I manage to create method in data access layer:
 
publicclassUser : iUser
    {
        //private cdwEntities db = new cdwEntities();
private cdwEntities2 db;
        public User(cdwEntities2 ctx)
        {
            db = ctx;
        }
 

        publicbool Login(string UserName, string Password)
        {
            var user = db.api_login.FirstOrDefault(u => u.username == UserName
                     && u.password == Password);
 
            if (user != null)
            {
                if (user.password == Password)
                {
                    returntrue;
                }
            }
 
            returnfalse;
        }
 
    }
 
Can I use login method in userPro class and if so, any guidelines or framework i could use to construct the above method/class.
Thank you for your time and help.

Viewing all articles
Browse latest Browse all 3938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>