Guest User

Login.aspx

a guest
Mar 4th, 2015
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Security;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Globalization;
  9.  
  10. namespace FormsAuthenticateProject.Account
  11. {
  12.     public partial class Login : System.Web.UI.Page
  13.     {
  14.         DBConnLayer DBCL = new DBConnLayer();
  15.         ////oddly named as to not interfere with other students cookies if they chose to use them
  16.         //HttpCookie cookie = new HttpCookie("Session0000");
  17.         string DTFormat = "dd-MM-yyyy HH:mm:ss";
  18.  
  19.         protected void Page_Load(object sender, EventArgs e)
  20.         {
  21.             txtMinutes.ReadOnly = !chkStayLoggedIn.Checked;            
  22.         }
  23.  
  24.         protected void btnLogin_Click(object sender, EventArgs e)
  25.         {
  26.             HttpCookie cookie = new HttpCookie("Session");
  27.  
  28.             string strUserName = txtUserName.Text;
  29.             string strPassword = txtPassword.Text;
  30.             string strSessionID = Session.SessionID;
  31.             double dbMinutesToStayLoggedIn = 0d;
  32.             double.TryParse(txtMinutes.Text, out dbMinutesToStayLoggedIn);
  33.             DateTime DTNow = DateTime.Now;
  34.             DateTime DTTimeToStaySignedIn = DTNow.AddMinutes(dbMinutesToStayLoggedIn);
  35.  
  36.             //Look into using RSA keys
  37.             string encPassword = DBCL.encodeToSHA1(strPassword);
  38.             string encSessionID = DBCL.encodeToSHA1(strSessionID);
  39.             bool blVerifiedLoggin = DBCL.verifyLogginCreds(strUserName, encPassword);
  40.  
  41.             if (blVerifiedLoggin)
  42.             {
  43.  
  44.                 cookie["ID"] = encSessionID;
  45.                 cookie["LogoutTimer"] = DTTimeToStaySignedIn.ToString(DTFormat);
  46.                 DBCL.modifySessionID(strSessionID, DTTimeToStaySignedIn.ToString(), strUserName);
  47.  
  48.                 if (chkStayLoggedIn.Checked)
  49.                 {
  50.                     cookie.Expires = DTTimeToStaySignedIn;
  51.                     Response.Cookies.Add(cookie);
  52.                 }
  53.                 else
  54.                 {
  55.                         cookie.Expires = DateTime.Now.AddMinutes(15);
  56.                         Response.Cookies.Add(cookie);
  57.                 }
  58.  
  59.                 if (DBCL.compareSessionID(cookie["ID"]))
  60.                 {
  61.                     Response.Redirect("~/Customer/default.aspx", false);
  62.                 }
  63.             }
  64.             else
  65.             {
  66.                 lblMsg.Text = "Password or Username incorrect.";
  67.                 lblMsg.Visible = true;
  68.             }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment