Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public partial class Login : System.Web.UI.Page
- {
- private void processLogin()
- {
- LoginContext log = new LoginContext();
- log.SetUser(txtEmail.Text, txtPassword.Text);
- if (log.DoLogin())
- {
- if (chkCookie.Checked)
- {
- HttpCookie cookie = createPersistantCookie(txtEmail.Text, 7);
- Response.Cookies.Clear();
- Response.Cookies.Add(cookie);
- }
- FormsAuthentication.SetAuthCookie(txtEmail.Text, true);
- Response.Redirect("~/Members/Default.aspx");
- }
- }
- }
- public class LoginContext
- {
- public string email { get; protected set; }
- public string password { get; protected set; }
- public void SetUser(string EmailAddress, string Password)
- {
- // set login details from the form - my first try at encapsulation
- email = EmailAddress;
- password = Password;
- }
- public bool DoLogin()
- {
- bool result = false;
- string cmdText = "Users_SelectByEmailAndPassword";
- List<MySqlParameter> args = new List<MySqlParameter>();
- args.Add(new MySqlParameter("xemail", MySqlDbType.VarChar));
- args[args.Count - 1].Value = email;
- args.Add(new MySqlParameter("xpassword", MySqlDbType.VarChar));
- args[args.Count - 1].Value = password;
- DataTable dt;
- // Database(string sql, System.Data.CommandType CommandType, List<MySqlParameter>)
- // also done this way for encapsulation
- using (Database db = new Database(cmdText, CommandType.StoredProcedure, args))
- {
- dt = db.GetDataTable();
- }
- if (dt != null)
- {
- populateSessionVars(dt.Rows[0]);
- result = true;
- }
- return result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement