public static string forgetpassword(string password, string uniqueId) { var db = new BetaDB(); string validpassword = password.ValidatePassword(); if (validpassword == "true") { var uuniqueId = Guid.Parse(uniqueId); var IsValid = db.GUIDs.Where(x => x.UniqueId.Equals(uuniqueId)).FirstOrDefault(); Login lg = db.Logins.Find(IsValid.UserId); lg.Password = HelpUs.Encrypt(password); db.Entry(lg).State = System.Data.Entity.EntityState.Modified; var deleteGUID = db.GUIDs.SingleOrDefault(x => x.UniqueId.Equals(IsValid.UniqueId)); db.Entry(deleteGUID).State = System.Data.Entity.EntityState.Deleted; db.SaveChanges(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Password reset successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "server error"); return(JsonConvert.SerializeObject(dic)); } }
public static string ChangePassword(string password, string newpassword) { string email = HttpContext.Current.Session["email"].ToString(); var db = new BetaDB(); var oldpassword = HelpUs.Encrypt(password); var newPassword = HelpUs.Encrypt(newpassword); var User = db.Logins.Where(x => x.Email == email).FirstOrDefault(); if (User.Password != oldpassword) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Old Password did not match"); return(JsonConvert.SerializeObject(dic)); } else if (User.Password == newPassword) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "New Password Cannot be same as before"); return(JsonConvert.SerializeObject(dic)); } else { string validpassword = newpassword.ValidatePassword(); if (validpassword == "true") { User.Password = HelpUs.Encrypt(newpassword); //db.Entry(lg).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Password Changed successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Password Must Contain Uppercase,Lowercase,Character and 8 Digits"); return(JsonConvert.SerializeObject(dic)); } } }
protected void BtnRegister_Click(object sender, EventArgs e) { using (var db = new BetaDB()) { if (db.Logins.Count((a) => a.Email == TxtEmail.Text) > 0) { lblMessage.Text = "sorry"; } else { var encryptedpassword = HelpUs.Encrypt(TxtPassword.Text); Login lg = new Login { Email = TxtEmail.Text, Password = encryptedpassword }; db.Logins.Add(lg); db.SaveChanges(); } } }
public static string register(string email, string password) { try { var db = new BetaDB(); if (!string.IsNullOrEmpty(email) && !string.IsNullOrWhiteSpace(email)) { var emailexist = db.Logins.FirstOrDefault(x => x.Email == email); if (emailexist == null) { // checking email format bool valid = email.ValidateEmail(); if (valid == true) { Login l = new Login(); // for password requirement string validpassword = password.ValidatePassword(); if (validpassword == "true") { l.Email = email; l.Password = HelpUs.Encrypt(password); l.UserRole = "User"; l.CreatedOn = DateTime.Now; l.IsActive = false; l.Islocked = false; db.Logins.Add(l); db.SaveChanges(); //to send activation email and save data in GUID data string purpose = "Activation"; GUID UniqueCode = NewGuid(l, purpose); string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Activation/" + UniqueCode.UniqueId); Sendemail(email, purpose, url); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "User Registered Successfully"); return(JsonConvert.SerializeObject(dic)); } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Password Must Contain Uppercase,Lowercase,Character and 8 Digits"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email is Invalid"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "User Already Exists"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email and Password Required"); return(JsonConvert.SerializeObject(dic)); } } catch (Exception e) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Server Error"); return(JsonConvert.SerializeObject(dic)); } }
public static string login(string email, string password) { using (var db = new BetaDB()) { if (!string.IsNullOrEmpty(email) && !string.IsNullOrWhiteSpace(email)) { var login = db.Logins.SingleOrDefault(x => x.Email == email); string Password = HelpUs.Encrypt(password); if (login != null && login.Password == Password) { //check if isemail varified if (login.IsActive == true) { HttpContext.Current.Session["email"] = login.Email; HttpContext.Current.Session["UserRole"] = login.UserRole; CartHandler carthandler = new CartHandler(); carthandler.SyncCookieDatainDb(); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "0"); dic.Add("Message", "Login Successfull "); dic.Add("RedirectUrl", "/Home"); return(JsonConvert.SerializeObject(dic)); } else { // To send a activation email if user forget to activate when register var guidId = db.GUIDs.FirstOrDefault(f => f.UserId == login.ID && f.Purpose == "Activation"); if (login.IsActive == false) { string purpose = "Activation"; if (guidId == null) { guidId = NewGuid(login, purpose); } string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Activation/" + guidId.UniqueId); Sendemail(email, guidId.Purpose, url); } else if (guidId != null && guidId.UserId != null && guidId.Purpose == "Activation") { string url = HttpContext.Current.Server.HtmlEncode(Domain + "/Activation/" + guidId.UniqueId); Sendemail(email, guidId.Purpose, url); } // guid is null Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Verify your Email first "); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Username or Password Do not Match"); dic.Add("RedirectUrl", "/Home"); return(JsonConvert.SerializeObject(dic)); } } else { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("Error", "1"); dic.Add("Message", "Email and Password Required"); return(JsonConvert.SerializeObject(dic)); } } }