internal void GeneratePassword() { try { PasswordGenerator pw = new PasswordGenerator(); string new_pass = pw.Generate(); this.plainpassword = new_pass; this.password = UDF.EncryptString(new_pass); } catch (Exception) {} }
internal void Save() { EcommercePlatformDataContext db = new EcommercePlatformDataContext(); PasswordGenerator pw = new PasswordGenerator(); string new_pass = pw.Generate(); // Make sure we don't have an account with this e-mail address Customer cust = this.GetCustomerByEmail(); if (cust != null && cust.ID > 0) { throw new Exception("An account using the E-Mail address you provided already exists."); } // We are going to make an attempt at saving the Customer record Customer new_customer = new Customer { email = this.email, fname = this.fname, lname = this.lname, phone = this.phone, dateAdded = this.dateAdded, isSuspended = this.isSuspended, isValidated = this.isValidated, validator = this.validator, password = this.password, receiveNewsletter = this.receiveNewsletter, receiveOffers = this.receiveOffers, }; db.Customers.InsertOnSubmit(new_customer); db.SubmitChanges(); this.ID = new_customer.ID; SendNotification(); }
private static string SetNewPassword(int profile_id) { try { // Retrieve the Profile record EcommercePlatformDataContext db = new EcommercePlatformDataContext(); Profile prof = db.Profiles.Where(x => x.id.Equals(profile_id)).FirstOrDefault<Profile>(); if (prof == null) { throw new Exception(); } // Generate a new password string pwd = new PasswordGenerator().Generate(); prof.password = Crypto.EncryptString(pwd); // Save the profile and return the new password db.SubmitChanges(); return pwd; } catch (Exception) { throw new Exception("Failed to update password."); } }