Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Login.aspx.cs
- namespace stman
- {
- public partial class Login : System.Web.UI.Page
- {
- protected void btnLogin_Click(object sender, EventArgs e)
- {
- if (Page.IsValid)
- {
- processLogin();
- }
- }
- protected void processLogin()
- {
- LoginContext log = new LoginContext();
- if (log.DoLogin(txtEmail.Text, txtPassword.Text))
- {
- FormsAuthentication.SetAuthCookie(txtEmail.Text, True);
- Response.Redirect("Members/Default.aspx");
- }
- }
- }
- }
- // App_Code/LoginContext.cs
- namespace stman
- {
- public class LoginContext
- {
- public bool DoLogin(string email, string password)
- {
- bool result = false;
- string cmdText = "Users_SelectByEmailAndPassword";
- List<MySqlParameter> args = new List<MySqlParameter>();
- args.Add(new MySqlParameter("@email", MySqlDbType.VarChar));
- args[args.Count - 1].Value = email;
- args.Add(new MySqlParameter("@password", MySqlDbType.VarChar));
- args[args.Count - 1].Value = password;
- DataTable dt;
- // Database is just a class that handles the database queries and returns the data
- using (Database db = new Database(cmdText, CommandType.StoredProcedure, args))
- {
- dt = db.GetDataTable();
- }
- if (dt != null)
- {
- populateSessionVars(dt.Rows[0]);
- result = true;
- }
- return result;
- }
- private void populateSessionVars(DataRow row)
- {
- HttpContext.Current.Session["userid"] = row["userid"];
- HttpContext.Current.Session["emailaddress"] = row["email"];
- HttpContext.Current.Session["firstname"] = row["firstname"];
- HttpContext.Current.Session["lastname"] = row["lastname"];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement