public ActionResult Login(tblUserAccount model, string returnUrl) { var dataItem = db.tblUserAccounts.Where(x => x.Username == model.Username && x.Password == model.Password).FirstOrDefault(); if (dataItem != null) { FormsAuthentication.SetAuthCookie(dataItem.Username, false); if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) { Session["loginID"] = dataItem.UserID; return(Redirect(returnUrl)); } else { Session["loginID"] = dataItem.UserID; return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Invalid user/pass"); return(View()); } }
public ActionResult Register(tblUserAccount model) { tblUserAccount tbl = new tblUserAccount(); if (ModelState.IsValid) { if (db.tblUserAccounts.Any(x => x.Username == model.Username)) { ModelState.AddModelError("username", "username is not available"); } else { Guid guid = Guid.NewGuid(); tbl.UserID = guid; tbl.Username = model.Username; tbl.Password = model.Password; db.tblUserAccounts.Add(tbl); db.SaveChanges(); return(RedirectToAction("Login", "Account")); } } return(View()); }
protected void btnRegister_Click(object sender, EventArgs e) { tblUserAccount users = new tblUserAccount(); SmtpClient smtp = new SmtpClient(); MailMessage message = new MailMessage(); string encryptedpassword = FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "SHA1"); if (Page.IsValid) { if (db.tblUserAccounts.Any(u => u.Email == txtEmail.Text)) { Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('" + "Email already exists!" + "');", true); txtEmail.Focus(); } else { users.CompanyName = txtCompanyName.Text; users.Address = txtAddress.Text; users.Phone = txtPhone.Text; users.Website = txtWebsite.Text; users.Password = encryptedpassword; users.Email = txtEmail.Text; //string FolderName = Path.Combine(Server.MapPath("~/CompanyFiles"), txtCompanyName.Text); //if (!System.IO.Directory.Exists(FolderName)) //{ // System.IO.Directory.CreateDirectory(FolderName); //} //users.Folder = FolderName; if (ddlCompanyType.SelectedItem.ToString() == "Consultant") { users.RoleId = 2; users.CompanyTypeId = 1; } else if (ddlCompanyType.SelectedItem.ToString() == "Vendor") { users.RoleId = 3; users.CompanyTypeId = 2; } else if (ddlCompanyType.SelectedItem.ToString() == "Both (Consultant & Vendor)") { users.RoleId = 3; users.CompanyTypeId = 3; } else if (ddlCompanyType.SelectedItem.ToString() == "Client") { users.RoleId = 4; users.CompanyTypeId = 4; } db.tblUserAccounts.Add(users); db.SaveChanges(); MailAddress fromAddress = new MailAddress("MEPBD <*****@*****.**>"); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.EnableSsl = true; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; message.From = fromAddress; message.To.Add(txtEmail.Text); NetworkCredential credentials = new NetworkCredential("*****@*****.**", "ghost9990"); smtp.UseDefaultCredentials = false; smtp.Credentials = credentials; message.Subject = "Your MEPBD membership credentials"; message.Body = "Username: "******"<br />" + "Password: "******"<br />" + "Please save your credentials in a secure space." + "<br />" + "Click " + "<a href=\"http://localhost:2257/Generic/Login.aspx\">here</a>" + " to login."; message.IsBodyHtml = true; smtp.Send(message); ScriptManager.RegisterStartupScript(this, GetType(), "", "alert('Registered successfully. Please check your provided email for MEPBD account information.');location.href='Login.aspx'", true); //Page.ClientScript.RegisterStartupScript(GetType(), // "msgbox", "alert('" + "Registered Successfully!" + " Username: "******" | " + " Password: "******"\n" + " An email was sent to your email account." + "');", true); } } }