You must Sign In to post a response.
  • Category: ASP.NET

    About authencation in asp.net

    Any one can tell me the code how can go to the admin and user through login with username and password wit authentication.
  • #767611
    Hi,

    In ASP.net we have 3 types of Authentications are available,

    1) Windows Authentication
    2) forms Authentication
    3) Passport Authentication

    As per your requirement I suspect that you are looking Forms Authentication, it works based on login credentials, you have to save those details in your database and validate it for future reference, to setup the authentication type you can open the web config in your project solution and wrote below piece of code over there.


    <system.web>
    <authentication mode="Forms">
    <forms loginUrl="logon.aspx" name=".ASPXFORMSAUTH">
    </forms>
    </authentication>
    </system.web>


    For maintaining login credentials you may please refer below link this might be helpful to you how to maintain login info "aspsnippets.com/Articles/Simple-Form-based-authentication-example-in-ASPNet.aspx".

    Hope this helps you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #767619
    If you want to differentiate admin and user role wise authentication then you need to define ROLE at the time of user creation and store them in database, after validating username and password when you logged in your application you need to check role of logged in user and then redirect it as per the role, OR you can use form authentication and as per that you can authenticate user
    see below link
    https://msdn.microsoft.com/en-us/library/xdt4thhy.aspx

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #768216
    There can be 2 separate roles to different user and admin user:
    1. user
    2. admin

    Save these roles in the table while creating users – Users that will created from front-end website will have "user" role while you can provide both roles in admin where admin can choose if user need to be admin user or normal user.
    Now, you can check those roles while validating users like, when fetching user object from username and password and if the user object is not null then redirect user to areas as per roles and manage the state for the logged-in user.
    User userObject = GetUser(username, password);
    If(userObject!=null)
    {
    String role = userObject.Role ;

    //store the user ID and role in session to get the correct result and permission
    Session["UserID "] = userObject.UserID;
    Session["Role"] = userObject.Role;

    If(role=="admin")
    {
    //redirect to admin dashboard
    }
    else
    {
    //redirect to normal user page
    }
    }
    else
    {
    // Invalid username or password
    }
    Now, you can check for role from Session["Role"] object and see if the logged-in user has permission to access this page or not for the admin pages on page_load event. If the user does not have "admin" role then show the custom page showing "Not authorized " content.

    For any other .net related query, you can also contact our dotnet developer team.
    http://www.teaminindia.co.uk/hire-asp.net-developer.htm

  • #768265
    You can use following code snippet as example for Admin and user through login with username and password with authentication.
     unction login (email, password, callback) {
    var connection = mysql({
    host : 'localhost',
    user : 'Dotnetspider',
    password : 'memberid',
    database : 'exampledb'
    });
    connection.connect();
    var query = "SELECT id, nickname, email, password " +
    "FROM users WHERE email = ?";
    connection.query(query, [email], function (err, results) {
    if (err) return callback(err);
    if (results.length === 0) return callback();
    var user = results[0];
    if (!bcrypt.compareSync(password, user.password)) {
    return callback();
    }
    callback(null, {
    id: user.id.toString(),
    nickname: user.nickname,
    email: user.email
    });
    });
    }


Sign In to post your comments