SHARE
TWEET

Untitled

Ortund Jun 12th, 2013 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public partial class Login : System.Web.UI.Page
  2. {
  3.         private void processLogin()
  4.         {
  5.             LoginContext log = new LoginContext();
  6.             log.SetUser(txtEmail.Text, txtPassword.Text);
  7.  
  8.             if (log.DoLogin())
  9.             {
  10.                 if (chkCookie.Checked)
  11.                 {
  12.                     HttpCookie cookie = createPersistantCookie(txtEmail.Text, 7);
  13.                     Response.Cookies.Clear();
  14.                     Response.Cookies.Add(cookie);
  15.                 }
  16.  
  17.                 FormsAuthentication.SetAuthCookie(txtEmail.Text, true);
  18.                 Response.Redirect("~/Members/Default.aspx");
  19.             }
  20.         }
  21. }
  22.  
  23. public class LoginContext
  24. {
  25.         public string email { get; protected set; }
  26.         public string password { get; protected set; }
  27.  
  28.         public void SetUser(string EmailAddress, string Password)
  29.         {
  30.             // set login details from the form - my first try at encapsulation
  31.             email = EmailAddress;
  32.             password = Password;
  33.         }
  34.  
  35.         public bool DoLogin()
  36.         {
  37.             bool result = false;
  38.             string cmdText = "Users_SelectByEmailAndPassword";
  39.  
  40.             List<MySqlParameter> args = new List<MySqlParameter>();
  41.             args.Add(new MySqlParameter("xemail", MySqlDbType.VarChar));
  42.             args[args.Count - 1].Value = email;
  43.             args.Add(new MySqlParameter("xpassword", MySqlDbType.VarChar));
  44.             args[args.Count - 1].Value = password;
  45.  
  46.             DataTable dt;
  47.             // Database(string sql, System.Data.CommandType CommandType, List<MySqlParameter>)
  48.             // also done this way for encapsulation
  49.             using (Database db = new Database(cmdText, CommandType.StoredProcedure, args))
  50.             {
  51.                 dt = db.GetDataTable();
  52.             }
  53.  
  54.             if (dt != null)
  55.             {
  56.                 populateSessionVars(dt.Rows[0]);
  57.                 result = true;
  58.             }
  59.  
  60.             return result;
  61.         }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top