public void WriteCustomer(Customer c) { string sqlPerson = "Insert into Person(PersonLastName, PersonFirstName,PersonUserName,PersonPlainPassword,Personpasskey,PersonUserPassword,PersonEntryDate) Values(@LastName, @FirstName, @UserName, @PlainPassword, @Passcode, @HashedPassword, @EntryDate)"; string sqlPersonAddress = "Insert into PersonAddress(Street, Apartment, City, State, Zip, Personkey) " + "Values(@Street, @Apartment, @City, @State, @Zip, ident_Current('Person'))"; PasscodeGenerator pg = new PasscodeGenerator(); PasswordHash ph = new PasswordHash(); int Passcode = pg.GetPasscode(); SqlCommand personCmd = new SqlCommand(sqlPerson, connect); personCmd.Parameters.AddWithValue("@FirstName", c.FirstName); personCmd.Parameters.AddWithValue("@LastName", c.LastName); personCmd.Parameters.AddWithValue("@UserName", c.Email); personCmd.Parameters.AddWithValue("@PlainPassword", c.PlainPassword); personCmd.Parameters.AddWithValue("@Passcode", Passcode); personCmd.Parameters.AddWithValue("@HashedPassword", ph.HashIt(c.PlainPassword.ToString(), Passcode.ToString())); personCmd.Parameters.AddWithValue("@EntryDate", DateTime.Now); SqlCommand addressCmd = new SqlCommand(sqlPersonAddress, connect); addressCmd.Parameters.AddWithValue("@Street", c.Street); addressCmd.Parameters.AddWithValue("@Apartment", c.Apartment); addressCmd.Parameters.AddWithValue("@City", c.City); addressCmd.Parameters.AddWithValue("@State", c.State); addressCmd.Parameters.AddWithValue("@Zip", c.Zip); connect.Open(); personCmd.ExecuteNonQuery(); addressCmd.ExecuteNonQuery(); connect.Close(); }
private SqlCommand WriteRegisteredCustomer() { PasscodeGenerator pg = new PasscodeGenerator(); PasswordHash ph = new PasswordHash(); int passcode = pg.GetPasscode(); string sqlRegisteredCustomer = "Insert into Customer.RegisteredCustomer(Email, Passcode, CustomerPassword, CustomerHashedPassword, PErsonKey) " + "Values(@Email, @Passcode, @Password, @Hashedpass, identCurrent('Person'))"; SqlCommand regCustomerCmd = new SqlCommand(sqlRegisteredCustomer, connect); regCustomerCmd.Parameters.AddWithValue("@Email", c.Email); regCustomerCmd.Parameters.AddWithValue("@Passcode", pg.GetPasscode()); regCustomerCmd.Parameters.AddWithValue("@Password", c.Password); regCustomerCmd.Parameters.AddWithValue("@hashedPass", ph.HashIt(c.Password.ToString(), passcode.ToString())); return(regCustomerCmd); }
/*private SqlCommand WritePerson() * { * string sqlPerson = "Insert into Person (LastName, FirstName) Values (@LastName, @FirstName)"; * SqlCommand personCmd = new SqlCommand(sqlPerson, connect); * personCmd.Parameters.AddWithValue("@LastName", c.LastName); * personCmd.Parameters.AddWithValue("@FirstName", c.FirstName); * return personCmd; * }*/ public void WriteContributor(NewContributor ncont) { //this.cust=c; //SqlTransaction tran = null; //SqlCommand pCmd = WritePerson(); string sqlPerson = "Insert into Person (PersonLastName, PersonFirstName, PersonUsername, PersonPlainPassword, Personpasskey, PersonUserPassword) " + "Values (@LastName, @FirstName, @Username, @PlainPW, @PersonPassKey, @PersonUserPassword)"; string sqlPersonAddress = "Insert into PersonAddress (Street, City, State, Zip, PersonKey) " + "Values(@Street, @City, @State, @Zip, ident_Current('Person'))"; //string sqlRegisteredCustomer = "Insert into customer.RegisteredCustomer(Email, CustomerPassCode, CustomerPassword, CustomerHashedPassword, PersonKey) " + //"Values(@Email, @Passcode, @password, @hashedpass, ident_Current('Person'))"; PasscodeGenerator pg = new PasscodeGenerator(); PasswordHash ph = new PasswordHash(); int passcode = pg.GetPasscode(); SqlCommand newContributorCmd = new SqlCommand(sqlPerson, connect); newContributorCmd.Parameters.AddWithValue("@LastName", ncont.lastName); newContributorCmd.Parameters.AddWithValue("@FirstName", ncont.firstName); newContributorCmd.Parameters.AddWithValue("@Username", ncont.email); newContributorCmd.Parameters.AddWithValue("@PlainPW", ncont.plainTextPassword); newContributorCmd.Parameters.AddWithValue("@PersonPassKey", passcode); newContributorCmd.Parameters.AddWithValue("@PersonUserPassword", ph.HashIt(ncont.plainTextPassword, passcode.ToString())); //SqlCommand regCustomerCmd = new SqlCommand(sqlRegisteredCustomer, connect); //regCustomerCmd.Parameters.AddWithValue("@Passcode", passcode); //regCustomerCmd.Parameters.AddWithValue("@password", c.PlainPassword); //regCustomerCmd.Parameters.AddWithValue("@hashedpass", ph.HashIt(c.PlainPassword, passcode.ToString())); SqlCommand personAddressCmd = new SqlCommand(sqlPersonAddress, connect); personAddressCmd.Parameters.AddWithValue("@Street", ncont.streetAddress); personAddressCmd.Parameters.AddWithValue("@City", ncont.city); personAddressCmd.Parameters.AddWithValue("@State", ncont.state); personAddressCmd.Parameters.AddWithValue("@Zip", ncont.postalCode); connect.Open(); //try { //tran = commenct.BeginTransation(); //pCmd.Transaction = tran; //pCmd.ExecuteNonQuery(); //tran.Commit(); newContributorCmd.ExecuteNonQuery(); personAddressCmd.ExecuteNonQuery(); //}catch(Exception ex){ //tran.Rollback(); //throw ex; //}finally{ connect.Close(); //} }
protected void btnSubmit_Click(object sender, EventArgs e) { //get the passcode PasscodeGenerator pg = new PasscodeGenerator(); int passcode = pg.GetPasscode(); //initialize customer and vehicle Customer c = new Customer(); Vehicle v = new Vehicle(); //initialize PasswordHash PasswordHash ph = new PasswordHash(); //Assign the values from the textboxes //to the classes c.LastName = txtLastName.Text; c.FirstName = txtFirstName.Text; c.email = txtEmail.Text; c.password = txtPassword.Text; c.passcode = passcode; //get the hashed password c.PasswordHash = ph.Hashit(txtPassword.Text, passcode.ToString()); c.apartment = txtApt.Text; c.state = txtState.Text; c.street = txtStreet.Text; c.zip = txtZip.Text; c.city = txtCity.Text; c.phone = txtPhone.Text; // v.License = txtLicense.Text; //v.Make = txtMake.Text; // v.Year = txtYear.Text; try { //try to write to the database Registrations r = new Registrations(c); lblResult.Text = "Thank you for registering"; LinkButton1.Visible = true; } catch (Exception ex) { //if it fails show the error lblError.Text = ex.ToString(); } }
protected void btnSubmit_Click(object sender, EventArgs e) { try { CommunityAssistEntities ce = new CommunityAssistEntities(); Person p = new Person(); p.PersonFirstName = txtFirstName.Text; p.PersonLastName = txtLastName.Text; p.PersonUsername = txtEmail.Text; p.PersonPlainPassword = txtConfirm.Text; PasscodeGenerator pg = new PasscodeGenerator(); int passcode = pg.GetPasscode(); PasswordHash ph = new PasswordHash(); p.Personpasskey = passcode; p.PersonUserPassword = ph.Hashit(txtConfirm.Text, passcode.ToString()); ce.People.Add(p); //vehicle v = new vehicle(); //v.LicenseNumber = txtLicense.Text; //v.VehicleMake = txtMake.Text; //v.VehicleYear = ddYear.SelectedItem.ToString(); //v.Person = p; //ce.vehicles.Add(v); //PasscodeGenerator pg = new PasscodeGenerator(); //int passcode = pg.GetPasscode(); //PasswordHash ph = new PasswordHash(); //RegisteredCustomer rc = new RegisteredCustomer(); //rc.Person = p; //rc.Email = txtEmail.Text; //rc.CustomerPassCode = passcode; //rc.CustomerPassword = txtConfirm.Text; //rc.CustomerHashedPassword = ph.Hashit(txtConfirm.Text, passcode.ToString()); //ce.Person.Add(p); ce.SaveChanges(); Response.Redirect("Welcome.aspx"); } catch (Exception ex) { lblResult.Text = ex.Message; } }
private SqlCommand WriteRegisteredCustomer() { PasscodeGenerator pg = new PasscodeGenerator(); PasswordHash ph = new PasswordHash(); int passcode = pg.GetPasscode(); string sqlRegisteredCustomer = "Insert into Customer.RegisteredCustomer(Email, Passcode, CustomerPassword, CustomerHashedPassword, PErsonKey) " + "Values(@Email, @Passcode, @Password, @Hashedpass, identCurrent('Person'))"; SqlCommand regCustomerCmd = new SqlCommand(sqlRegisteredCustomer, connect); regCustomerCmd.Parameters.AddWithValue("@Email", c.Email); regCustomerCmd.Parameters.AddWithValue("@Passcode", pg.GetPasscode()); regCustomerCmd.Parameters.AddWithValue("@Password", c.Password); regCustomerCmd.Parameters.AddWithValue("@hashedPass", ph.HashIt(c.Password.ToString(), passcode.ToString())); return regCustomerCmd; }
/* Cannot insert explicit value for identity column in table 'Person' when IDENTITY_INSERT is set to OFF. */ private SqlCommand WritePerson() { PasscodeGenerator pg = new PasscodeGenerator(); PasswordHash ph = new PasswordHash(); int passcode = pg.GetPasscode(); string sqlPerson = "Insert into Person ( PersonLastName, PersonFirstName, PersonUsername,Personpasskey, PersonUserPassword) Values (@LastName, @FirstName, @passcode, @password, @hashedpass)"; SqlCommand personCmd = new SqlCommand(sqlPerson, connect); personCmd.Parameters.AddWithValue("@LastName", p.lastName); personCmd.Parameters.AddWithValue("@FirstName", p.firstName); personCmd.Parameters.AddWithValue("@Email", p.email); personCmd.Parameters.AddWithValue("@Passcode", passcode.ToString()); personCmd.Parameters.AddWithValue("@password", p.passWord.ToString()); personCmd.Parameters.AddWithValue("@hashedPass", ph.HashIt(p.PlainPassword, passcode.ToString())); /*Cannot insert explicit value for identity column in table 'Person' when IDENTITY_INSERT is set to OFF. */ return(personCmd); }
public void WriteCustomer(Customer c) { this.c = c; SqlTransaction tran = null; SqlCommand pCmd = WritePerson(); SqlCommand vCmd = WriteVehicle(); SqlCommand rCmd = WriteRegisteredCustomer(); connect.Open(); try { tran = connect.BeginTransaction(); pCmd.Transaction = tran; vCmd.Transaction = tran; rCmd.Transaction = tran; pCmd.ExecuteNonQuery(); vCmd.ExecuteNonQuery(); rCmd.ExecuteNonQuery(); tran.Commit(); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { connect.Close(); } PasscodeGenerator pg = new PasscodeGenerator(); PasswordHash ph = new PasswordHash(); int passcode = pg.GetPasscode(); }
protected void btnSubmit_Click(object sender, EventArgs e) { //get the passcode PasscodeGenerator pg = new PasscodeGenerator(); int passcode = pg.GetPasscode(); //initialize customer and vehicle Customer c = new Customer(); Vehicle v = new Vehicle(); //initialize PasswordHash PasswordHash ph = new PasswordHash(); //Assign the values from the textboxes //to the classes c.LastName = txtLastName.Text; c.FirstName = txtFirstName.Text; c.email = txtEmail.Text; c.password = txtPassword.Text; c.passcode = passcode; //get the hashed password c.PasswordHash = ph.HashIt(txtPassword.Text, passcode.ToString()); v.License = txtLicense.Text; v.Make = txtMake.Text; v.Year = txtYear.Text; try { //try to write to the database Registration r = new Registration(c, v); lblResult.Text = "Thank you for registering"; LinkButton1.Visible = true; } catch (Exception ex) { //if it fails show the error lblError.Text = ex.ToString(); } }
public void WriteCustomer(Customer c) { string sqlPerson = "Insert into Person (LastName, Firstname) Values(@LastName, @FirstName)"; string sqlVehicle = " Insert into Customer.Vehicle(LicenseNumber, VehicleMake, VehicleYear, PersonKey) " + "Values(@License, @Make, @Year, ident_Current('Person'))"; string sqlRegisteredCustomer = "Insert into Customer.RegisteredCustomer(Email,CustomerPasscode, " + "CustomerPassword, CustomerHashedPassword, PersonKey) " + "Values(@email, @Passcode, @password, @hashedpass, ident_Current('Person'))"; SqlCommand personCmd = new SqlCommand(sqlPerson, connect); personCmd.Parameters.AddWithValue("@LastName", c.LastName); personCmd.Parameters.AddWithValue("@FirstName", c.FirstName); SqlCommand vehicleCmd = new SqlCommand(sqlVehicle, connect); vehicleCmd.Parameters.AddWithValue("@License", c.LicenseNumber); vehicleCmd.Parameters.AddWithValue("@Make", c.VehicleMake); vehicleCmd.Parameters.AddWithValue("@Year", c.VehicleYear); PasscodeGenerator pg = new PasscodeGenerator(); PasswordHash ph = new PasswordHash(); int passcode = pg.GetPasscode(); SqlCommand regCustomerCmd = new SqlCommand(sqlRegisteredCustomer, connect); regCustomerCmd.Parameters.AddWithValue("@Email", c.Email); regCustomerCmd.Parameters.AddWithValue("@Passcode", passcode); regCustomerCmd.Parameters.AddWithValue("@password", c.PlainPassword); regCustomerCmd.Parameters.AddWithValue("@hashedPass", ph.HashIt(c.PlainPassword.ToString(), passcode.ToString())); connect.Open(); personCmd.ExecuteNonQuery(); vehicleCmd.ExecuteNonQuery(); regCustomerCmd.ExecuteNonQuery(); connect.Close(); }
/* Cannot insert explicit value for identity column in table 'Person' when IDENTITY_INSERT is set to OFF. */ private SqlCommand WritePerson() { PasscodeGenerator pg = new PasscodeGenerator(); PasswordHash ph = new PasswordHash(); int passcode = pg.GetPasscode(); string sqlPerson = "Insert into Person ( PersonLastName, PersonFirstName, PersonUsername,Personpasskey, PersonUserPassword) Values (@LastName, @FirstName, @passcode, @password, @hashedpass)"; SqlCommand personCmd = new SqlCommand(sqlPerson, connect); personCmd.Parameters.AddWithValue("@LastName", p.lastName); personCmd.Parameters.AddWithValue("@FirstName", p.firstName); personCmd.Parameters.AddWithValue("@Email", p.email); personCmd.Parameters.AddWithValue("@Passcode", passcode.ToString()); personCmd.Parameters.AddWithValue("@password", p.passWord.ToString()); personCmd.Parameters.AddWithValue("@hashedPass", ph.HashIt(p.PlainPassword, passcode.ToString())); /*Cannot insert explicit value for identity column in table 'Person' when IDENTITY_INSERT is set to OFF. */ return personCmd; }