public static UserAuth login(membership param) { using (conferenceadminContext contx = new conferenceadminContext()) { /*UserAuth user = (from g in contx.memberships join u in contx.users on g.membershipID equals u.membershipID where g.email == param.email && g.password.Equals(param.password) && g.deleted == false && u.deleted == false select new UserAuth { userID = u.userID, memberID = g.membershipID, password = g.password, email = g.email, userType = u.userTypeID }).FirstOrDefault(); */ //copy paste del query de maria, solo quite: && g.password.Equals(param.password) del where clause y anadi: passwordSalt = g.passwordSalt, al select UserAuth user = (from g in contx.memberships join u in contx.users on g.membershipID equals u.membershipID where g.email == param.email && g.deleted == false && u.deleted == false select new UserAuth { userID = u.userID, memberID = g.membershipID, password = g.password, email = g.email, userType = u.userTypeID }).FirstOrDefault(); if (user == null) { return null; } else { var crypto = new SimpleCrypto.PBKDF2(); if (Security.ValidateSHA1HashData(param.password, user.password)) // if( string.Equals(crypto.Compute(param.password, user.passwordSalt), user.password, StringComparison.Ordinal)) return user; else{ return null; } } } }
/* [Randy] Add new registration entry */ public string addRegistration(registration reg, user user, membership mem) { /*int type, string firstname, string lastname, string affiliationName, bool registrationstatus, bool hasapplied, bool acceptancestatus*/ try { using (conferenceadminContext context = new conferenceadminContext()) { address address = new address(); context.addresses.Add(address); //encryption var userPassword = mem.password; mem.password = Security.GetSHA1HashData(mem.password); //end encryption mem.emailConfirmation = true; mem.deleted = false; context.memberships.Add(mem); context.SaveChanges(); user.addressID = address.addressID; user.membershipID = mem.membershipID; user.registrationStatus = "Accepted"; user.hasApplied = true; user.acceptanceStatus = "Accepted"; user.title = ""; user.phone = ""; user.userFax = ""; user.deleted = false; context.users.Add(user); context.SaveChanges(); reg.userID = user.userID; reg.paymentID = 1; reg.byAdmin = true; reg.deleted = false; context.registrations.Add(reg); context.SaveChanges(); try { sendEmailConfirmation(mem.email, userPassword); } catch (Exception ex) { Console.Write("AdminManager.ConfirmationEmail error " + ex); return null; } return reg.registrationID + "," + user.userTypeID; } } catch (Exception ex) { Console.Write("AdminManager.addRegistration error " + ex); return null; } }
public bool createUser(user user, membership member, address address) { try { string key = generateEmailConfirmationKey(); using (conferenceadminContext context = new conferenceadminContext()) { //code for password encryption var encrpPass = Security.GetSHA1HashData(member.password); member.password = encrpPass; //end password encryption member.deleted = false; member.emailConfirmation = false; member.deleted = false; member.confirmationKey = key; context.memberships.Add(member); context.SaveChanges(); context.addresses.Add(address); context.SaveChanges(); user.addressID = address.addressID; user.membershipID = member.membershipID; user.acceptanceStatus = "Pending"; user.deleted = false; user.hasApplied = false; user.registrationStatus = "Pending"; user.evaluatorStatus = user.evaluatorStatus; context.users.Add(user); context.SaveChanges(); if (user.userTypeID == 1) { minor minor = new minor(); minor.authorizationStatus = false; minor.deleted = false; minor.userID = user.userID; context.minors.Add(minor); context.SaveChanges(); } else if (user.userTypeID == 7) { sponsor2 sponsor = new sponsor2(); sponsor.deleted = false; sponsor.userID = user.userID; sponsor.active = false; sponsor.sponsorType = 5; sponsor.byAdmin = false; sponsor.active = false; sponsor.totalAmount = 0; payment payment2 = new payment(); payment2.paymentTypeID = 1; payment2.deleted = false; payment2.creationDate = DateTime.Now; context.payments.Add(payment2); context.SaveChanges(); sponsor.paymentID = payment2.paymentID; context.sponsor2.Add(sponsor); context.SaveChanges(); } else if (user.userTypeID == 6) { companion companion = new companion(); companion.deleted = false; companion.userID = user.userID; companion.companionKey = "Companion "+ user.userID + generateEmailConfirmationKey().Substring(0, 9); context.companions.Add(companion); context.SaveChanges(); } try { sendEmailConfirmation(member.email, member.confirmationKey); } catch (Exception ex) { Console.Write("SignUpManager.NewConfirmationEmail error " + ex); return false; } return true; } } catch (Exception ex) { Console.Write("SignUpManager.creatingUser error " + ex); return false; } }