ProTech's home page

ProTech-Online.com

Microsoft c# ASPX code example for user login.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Web.Security;
public partial class sans_login : System.Web.UI.Page
{
    protected void ProcessLogin(System.Web.UI.WebControls.Login sender)
    {
        try
        {
            SqlConnection myConnection = new SqlConnection(WebConfigurationManager.ConnectionStrings["TestConnectionString"].ToString());
            myConnection.Open();
            SqlCommand myCommand = new SqlCommand("delete_sessions", myConnection);
            myCommand.CommandType = System.Data.CommandType.StoredProcedure;
            myCommand.Parameters.AddWithValue("@userid", sender.UserName);
            int x = myCommand.ExecuteNonQuery();
            myCommand.CommandText = "create_sessions";
            Guid newSessionId = Guid.NewGuid();
            string tmpstr = Context.Request.UserAgent +
                            Context.Request.ServerVariables["REMOTE_ADDR"];
            string hashed = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(tmpstr, "SHA1");
            myCommand.Parameters.AddWithValue("@sessionid", newSessionId);
            myCommand.Parameters.AddWithValue("@clienthash", hashed);
            myCommand.Parameters.AddWithValue("@timeout", DateTime.Now.AddMinutes(30));
            x = myCommand.ExecuteNonQuery();
            myConnection.Close();
            Session["SoftwareID"] = newSessionId.ToString();
            //DeleteCart();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}


Copyright © 2013 ProTechs-Online.com; All rights reserved.