Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Security;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Globalization;
- namespace FormsAuthenticateProject.Account
- {
- public partial class Login : System.Web.UI.Page
- {
- DBConnLayer DBCL = new DBConnLayer();
- ////oddly named as to not interfere with other students cookies if they chose to use them
- //HttpCookie cookie = new HttpCookie("Session0000");
- string DTFormat = "dd-MM-yyyy HH:mm:ss";
- protected void Page_Load(object sender, EventArgs e)
- {
- txtMinutes.ReadOnly = !chkStayLoggedIn.Checked;
- }
- protected void btnLogin_Click(object sender, EventArgs e)
- {
- HttpCookie cookie = new HttpCookie("Session");
- string strUserName = txtUserName.Text;
- string strPassword = txtPassword.Text;
- string strSessionID = Session.SessionID;
- double dbMinutesToStayLoggedIn = 0d;
- double.TryParse(txtMinutes.Text, out dbMinutesToStayLoggedIn);
- DateTime DTNow = DateTime.Now;
- DateTime DTTimeToStaySignedIn = DTNow.AddMinutes(dbMinutesToStayLoggedIn);
- //Look into using RSA keys
- string encPassword = DBCL.encodeToSHA1(strPassword);
- string encSessionID = DBCL.encodeToSHA1(strSessionID);
- bool blVerifiedLoggin = DBCL.verifyLogginCreds(strUserName, encPassword);
- if (blVerifiedLoggin)
- {
- cookie["ID"] = encSessionID;
- cookie["LogoutTimer"] = DTTimeToStaySignedIn.ToString(DTFormat);
- DBCL.modifySessionID(strSessionID, DTTimeToStaySignedIn.ToString(), strUserName);
- if (chkStayLoggedIn.Checked)
- {
- cookie.Expires = DTTimeToStaySignedIn;
- Response.Cookies.Add(cookie);
- }
- else
- {
- cookie.Expires = DateTime.Now.AddMinutes(15);
- Response.Cookies.Add(cookie);
- }
- if (DBCL.compareSessionID(cookie["ID"]))
- {
- Response.Redirect("~/Customer/default.aspx", false);
- }
- }
- else
- {
- lblMsg.Text = "Password or Username incorrect.";
- lblMsg.Visible = true;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment