Ejemplo n.º 1
0
        static private bool generateUserPassword(string Username)
        {
            StringBuilder builder = new StringBuilder();

            byte[] ByteCode = getByteString(8);
            foreach (byte b in ByteCode)
            {
                builder.Append(b.ToString("X2"));
            }
            string newPassword = builder.ToString();

            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);

            foreach (NuRacingDataSet.UserRow userRow in userTable.Rows)
            {
                if (userRow.User_Username.ToLower() == Username.ToLower())
                {
                    byte[] salt = CreateSalt();
                    byte[] hash = HashPassword(newPassword, salt);

                    userRow.User_PasswordHash = hash;
                    userRow.User_PasswordSalt = salt;

                    userAdapter.Update(userTable);


                    try
                    {
                        EmailManager.sendPasswordResetEmail(Username, newPassword, userRow.User_Email);
                        return(true);
                    }
                    catch (Exception)
                    {
                        return(false);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 2
0
        static public UserInfo addUser(string Username, string Password, string UserRole, string GivenName, string Surname, string Email, string StudentNumber,
                                       string YearOfGradutation, string DegreeName, string MedicareNumber, string Allergies, string MedicalConditions, string DietaryRequirements,
                                       bool IndemnityFormSigned, string SAEMembershipNumber, DateTime SAEExpiryDate, string CAMSMembershipNumber, string CAMSLicenseType,
                                       string DriversLicenseNumber, string DriversLicenseState, string EmergencyContactName, string EmergencyContactPhoneNumber, bool IsActive = true)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetData();
            NuRacingDataSet.UserRow       userRow   = userTable.NewUserRow();

            if (UsernameExists(Username))
            {
                throw new ArgumentException("Username already exists");
            }
            if (!isEmailValid(Email))
            {
                throw new ArgumentException("Email isn't in a valid format");
            }
            if (EmailExists(Email))
            {
                throw new ArgumentException("Email already exists");
            }
            if (Password == "")
            {
                StringBuilder builder  = new StringBuilder();
                byte[]        ByteCode = getByteString(8);

                foreach (byte b in ByteCode)
                {
                    builder.Append(b.ToString("X2"));
                }

                Password = builder.ToString();
            }
            else if (!validPassword(Password))
            {
                throw new ArgumentException("Invalid Password");
            }
            if (!Role.UserRoles.Contains(UserRole))
            {
                throw new ArgumentException("Invalid Role");
            }


            byte[] Salt           = CreateSalt();
            byte[] HashedPassword = HashPassword(Password, Salt);

            userRow.User_Username               = Username;
            userRow.User_PasswordHash           = HashedPassword;
            userRow.User_PasswordSalt           = Salt;
            userRow.User_Role                   = UserRole;
            userRow.User_GivenName              = GivenName;
            userRow.User_Surname                = Surname;
            userRow.User_Email                  = Email;
            userRow.User_StudentNumber          = StudentNumber;
            userRow.User_EstGraduationYear      = YearOfGradutation;
            userRow.User_Degree                 = DegreeName;
            userRow.User_MedicareNo             = MedicareNumber;
            userRow.User_Allergies              = Allergies;
            userRow.User_MedicalConditions      = MedicalConditions;
            userRow.User_DietaryRequirements    = DietaryRequirements;
            userRow.User_IndemnityFormSigned    = IndemnityFormSigned;
            userRow.User_SAE_MemberNo           = SAEMembershipNumber;
            userRow.User_SAE_Expiry             = SAEExpiryDate;
            userRow.User_CAMS_MemberNo          = CAMSMembershipNumber;
            userRow.User_CAMS_LicenseType       = CAMSLicenseType;
            userRow.User_LicenseNo              = DriversLicenseNumber;
            userRow.User_LicenseState           = DriversLicenseState;
            userRow.User_EmergencyContactName   = EmergencyContactName;
            userRow.User_EmergencyContactNumber = EmergencyContactPhoneNumber;
            userRow.User_Active                 = IsActive;

            userRow.User_Created             = DateTime.Now;
            userRow.User_LastLogin           = DateTime.Now;
            userRow.User_LastActivity        = DateTime.Now;
            userRow.User_LastPasswordChanged = DateTime.Now;
            userRow.User_LastLockoutDate     = DateTime.Now;

            userTable.AddUserRow(userRow);
            userAdapter.Update(userTable);

            EmailManager.newUser(Username, Password, Email);

            return(UserInfo.getUser(Username));
        }