Esempio n. 1
0
        static public void setPassword(string Username, string NewPassword, string OldPassword)
        {
            string UserRole;

            if (!authenticateUser(Username, OldPassword, out UserRole))
            {
                throw new ArgumentException("Old Password was incorrect");
            }

            if (!validPassword(NewPassword))
            {
                throw new ArgumentException("Password wasn't valid");
            }

            if (UsernameExists(Username))
            {
                UserTableAdapter userAdapter            = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
                NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

                byte[] salt = CreateSalt();
                byte[] hash = HashPassword(NewPassword, salt);

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

                userAdapter.Update(userTable);
            }
            else
            {
                throw new ArgumentException("Username wasn't valid");
            }
        }
Esempio n. 2
0
        //  Written By James Hibbard
        ///
        /// <summary>
        ///     Checks whether the validity of the password
        /// </summary>
        /// <param name="Username">The users Username</param>
        /// <param name="Password">The input password to check</param>
        /// <param name="userRole">Returns the role they're in (null if incorrect password)</param>
        /// <returns>True if the password is accurate</returns>
        static public bool authenticateUser(string Username, string Password, out string userRole)
        {
            if (!UsernameExists(Username))
            {
                userRole = null;
                return(false);
            }

            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
            NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];


            if (userRow.User_Active)
            {
                if (userRow.User_PasswordHash.SequenceEqual(HashPassword(Password, userRow.User_PasswordSalt)))
                {
                    userRole = userRow.User_Role;
                    return(true);
                }
            }
            else
            {
                userRole = null;
                return(false);
            }

            userRole = null;
            return(false);
        }
Esempio n. 3
0
        //  Written By James Hibbard
        /// <summary>
        ///     Checks if the Username is stored in the database.
        /// </summary>
        /// <param name="Username">The Username to check</param>
        /// <returns>True if the username exists</returns>
        static public bool UsernameExists(string Username)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();

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

            return(userTable.Rows.Count != 0);
        }
Esempio n. 4
0
        public static string GetUserRole(string Username)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
            NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

            return(userRow.User_Role);
        }
Esempio n. 5
0
        public void resetData()
        {
            if (!beenChanged)
            {
                UserTableAdapter userAdapter            = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(username);
                NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

                setData(userRow);
            }
        }
Esempio n. 6
0
        //  Written By James Hibbard
        /// <summary>
        ///     Sets the Last Activity Date in the database for the given user
        /// </summary>
        /// <param name="Username">The User that was active</param>
        static public void wasActive(string Username)
        {
            if (UsernameExists(Username))
            {
                UserTableAdapter userAdapter            = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
                NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

                userRow.User_LastActivity = DateTime.Now;

                userAdapter.Update(userTable);
            }
        }
Esempio n. 7
0
        //  Written By James Hibbard
        /// <summary>
        ///     Gets the email for the given user
        /// </summary>
        /// <param name="Username"></param>
        /// <returns></returns>
        static public string getEmail(string Username)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();

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

            if (userTable.Rows.Count == 0)
            {
                throw new ArgumentException("Username wasn't a valid user");
            }
            else
            {
                return(userTable.Rows[0][userTable.User_EmailColumn].ToString());
            }
        }
Esempio n. 8
0
        static internal bool EmailExists(string Email)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetData();

            foreach (NuRacingDataSet.UserRow userRow in userTable.Rows)
            {
                if (userRow.User_Email == Email)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 9
0
        //Written By Simon Davis

        /// <summary>
        /// Returns a UserInfo object for the specified user
        /// </summary>
        /// <param name="Username">User's username</param>
        /// <returns></returns>

        static public UserInfo getUser(string Username)
        {
            if (!User.UsernameExists(Username))
            {
                throw new ArgumentException("Username wasn't valid");
            }

            UserTableAdapter userAdapter = new UserTableAdapter();

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

            NuRacingDataSet.UserRow userRow = (NuRacingDataSet.UserRow)userTable.Rows[0];

            UserInfo userInfo = new UserInfo(userRow);

            return(userInfo);
        }
Esempio n. 10
0
        public static string[] getUsersInRole(string RoleName)
        {
            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetData();

            List <string> results = new List <string>();

            foreach (NuRacingDataSet.UserRow userRow in userTable.Rows)
            {
                if (userRow.User_Role == RoleName)
                {
                    results.Add(userRow.User_Username);
                }
            }

            return(results.ToArray());
        }
Esempio n. 11
0
        //Written By Simon Davis

        /// <summary>
        /// Return a list of users of type UserInfo
        /// </summary>
        /// <returns></returns>

        static public List <UserInfo> getAllUsers(bool activeOnly = true)
        {
            List <UserInfo> userList = new List <UserInfo>();

            UserTableAdapter userAdapter = new UserTableAdapter();

            NuRacingDataSet.UserDataTable userTable = userAdapter.GetData();

            foreach (NuRacingDataSet.UserRow row in userTable.Rows)
            {
                if (row.User_Active || !activeOnly)
                {
                    userList.Add(new UserInfo(row));
                }
            }

            return(userList);
        }
Esempio n. 12
0
 public static void SetUserActiveStatus(string Username, bool active)
 {
     if (UsernameExists(Username))
     {
         UserTableAdapter userAdapter            = new UserTableAdapter();
         NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(Username);
         NuRacingDataSet.UserRow       userRow   = userTable[0];
         if (userRow.User_Active != active)
         {
             //avoid making the connection if possible
             userRow.User_Active = active;
             userAdapter.Update(userTable);
         }
     }
     else
     {
         throw new ArgumentException("Username wasn't valid");
     }
 }
Esempio n. 13
0
        public void updateDatabase()
        {
            if (beenChanged)
            {
                UserTableAdapter userAdapter            = new UserTableAdapter();
                NuRacingDataSet.UserDataTable userTable = userAdapter.GetUser(username);
                NuRacingDataSet.UserRow       userRow   = (NuRacingDataSet.UserRow)userTable.Rows[0];

                userRow.User_GivenName           = givenName;
                userRow.User_Surname             = surname;
                userRow.User_Email               = email;
                userRow.User_Role                = userRole;
                userRow.User_StudentNumber       = studentnumber;
                userRow.User_EstGraduationYear   = estimatedGraduationYear;
                userRow.User_Degree              = degree;
                userRow.User_MedicareNo          = medicareNumber;
                userRow.User_Allergies           = allergies;
                userRow.User_MedicareNo          = medicalConditions;
                userRow.User_DietaryRequirements = dietaryRequirements;
                userRow.User_IndemnityFormSigned = indemnityFormSigned;

                userRow.User_SAE_MemberNo = saeMembershipNumber;
                userRow.User_SAE_Expiry   = saeMembershipExpiry;

                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_Created             = dateCreated;
                userRow.User_LastLogin           = lastLoggedIn;
                userRow.User_LastActivity        = lastActivity;
                userRow.User_LastPasswordChanged = passwordLastChanged;
                userRow.User_LastLockoutDate     = lastLockedOut;
                userRow.User_Active = isActive;

                userAdapter.Update(userTable);
            }
        }
Esempio n. 14
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);
        }
Esempio n. 15
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));
        }