private void button1_Click(object sender, EventArgs e) { var userName = txtUsername.Text; var passWord = txtPassword.Text; var login = checkLogin(userName, HashPassword.CreateMD5(passWord)); if (login) { if (cbRemember.Checked) { Settings.Default.Username = userName; Settings.Default.Password = passWord; Settings.Default.Remember = cbRemember.Checked; } else { Settings.Default.Username = Settings.Default.Password = ""; Settings.Default.Remember = false; } Settings.Default.Save(); frmMain main = new frmMain(this); this.Hide(); main.ShowDialog(); this.Show(); } else { MessageBox.Show("Sai tài khoản hoặc mật khẩu!\nVui lòng nhập lại!"); } }
public HttpResponseMessage Login([FromBody] Traveler traveler) { using (Assignment2_ServicesContext db = new Assignment2_ServicesContext()) { db.Configuration.ProxyCreationEnabled = false; var v = db.Travelers.Where(a => a.email == traveler.email).FirstOrDefault(); if (v != null) { if (string.Compare(HashPassword.CreateMD5(traveler.password, v.salt), v.password) == 0 && v.IsEmailVerified == true) { return(Request.CreateResponse(HttpStatusCode.OK, v)); } else if (string.Compare(HashPassword.CreateMD5(traveler.password, v.salt), v.password) == 0 && v.IsEmailVerified == false) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Email does not active. Please active this email.")); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Password doesn't match.")); } } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Email does not exist.")); } } }
public HttpResponseMessage Register([Bind(Exclude = "IsEmailVerified,ActivationCode")][FromBody] Traveler traveler) { string message = ""; if (ModelState.IsValid) { #region //Email is already Exist var isExistEmail = IsEmailExist(traveler.email); if (isExistEmail) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Email already exist.")); } #endregion #region Generate Activation Code traveler.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing traveler.salt = GenerateSalt.saltStr(10); traveler.password = HashPassword.CreateMD5(traveler.password, traveler.salt); #endregion traveler.IsEmailVerified = false; #region Save to Database using (Assignment2_ServicesContext db = new Assignment2_ServicesContext()) { traveler.Role_id = 1; traveler.createdAt = DateTime.Now; traveler.updatedAt = DateTime.Now; Debug.WriteLine(JsonConvert.SerializeObject(traveler)); db.Travelers.Add(traveler); db.SaveChanges(); } //Send Email to User SendVerificationLinkEmail(traveler.email, traveler.ActivationCode.ToString()); message = "Registration successfully done. Account activation link " + " has been sent to your email id:" + traveler.email; return(Request.CreateResponse(HttpStatusCode.OK, traveler)); #endregion } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public ActionResult Login(PhotoUpload.Customer cus, string ReturnUrl = "") { string message = ""; using (AssignmentContext db = new AssignmentContext()) { var v = db.Customers.Where(a => a.email == cus.email).FirstOrDefault(); if (v != null) { if (!v.IsEmailVerified) { ViewBag.Message = "Please verify your email first"; return(View()); } if (string.Compare(HashPassword.CreateMD5(cus.password, v.salt), v.password) == 0) { if (v.status == 1) { var ticket = new FormsAuthenticationTicket(cus.email, true, 525600); string encrypted = FormsAuthentication.Encrypt(ticket); var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted); cookie.Expires = DateTime.Now.AddMinutes(525600); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { return(RedirectToAction("Index", "Login")); } } else if (v.status == 0 && v.IsEmailVerified == false) { message = "Your account can't active. Please active it."; } else if (v.status == -1) { message = "Your account has been ban."; } } else { message = "Invalid credential provided"; } } else { message = "Invalid credential provided"; } } ViewBag.Message = message; return(View()); }
public void Update() { User u = new User(); u.u_id = int.Parse(txtUid.Text); u.user_name = txtUserName.Text; u.password = txtPassword.Text == null ? lblpasshide.Text : HashPassword.CreateMD5(txtPassword.Text); u.status = chkStatus.Checked == true ? true : false; u.gender = chkGender.Checked == true ? true : false; u.full_name = txtName.Text; u.date_create = DateTime.Now; u.mobile = txtPhone.Text; u.email = txtEmail.Text; int result = UserDAO.Instance.Update(u); if (result > 0) { MessageBox.Show("Update success", "Update"); Load(); } }
public void Insert() { User u = new User(); u.user_name = txtUserName.Text; u.password = HashPassword.CreateMD5(txtPassword.Text); u.full_name = txtName.Text; u.gender = chkGender.Checked == true ? true : false; u.status = chkStatus.Checked == true ? true : false; u.email = txtEmail.Text; u.mobile = (txtPhone.Text); u.date_create = DateTime.Now; int result = UserDAO.Instance.Insert(u); if (result > 0) { MessageBox.Show("Insert succes", "Add New"); Load(); txtUid.Text = txtUserName.Text = txtName.Text = txtPhone.Text = txtEmail.Text = ""; chkGender.Checked = chkStatus.Checked = false; check = true; button2.Text = "Lưu"; } }
public ActionResult Register([Bind(Exclude = "IsEmailVerified,ActivationCode")] PhotoUpload.Customer cus) { bool Status = false; string message = ""; if (ModelState.IsValid) { #region //Email is already Exist var isExistEmail = IsEmailExist(cus.email); var isExistUsername = IsUsernameExist(cus.username); if (isExistEmail) { ModelState.AddModelError(cus.email, "Email already exist"); return(View(cus)); } else if (isExistUsername) { ModelState.AddModelError(cus.username, "Username already exist"); return(View(cus)); } #endregion #region Generate Activation Code cus.ActivationCode = Guid.NewGuid(); #endregion #region Password Hashing cus.salt = GenerateSalt.saltStr(10); cus.password = HashPassword.CreateMD5(cus.password, cus.salt); #endregion cus.IsEmailVerified = false; #region Save to Database using (AssignmentContext db = new AssignmentContext()) { db.Customers.Add(cus); db.SaveChanges(); } //Send Email to User SendVerificationLinkEmail(cus.email, cus.ActivationCode.ToString()); message = "Registration successfully done. Account activation link " + " has been sent to your email id:" + cus.email; Status = true; #endregion } else { message = "Invalid Request"; } ViewBag.Message = message; ViewBag.Status = Status; return(View(cus)); }