Exemplo n.º 1
0
        public void Issue_821__Old_user_accounts_no_longer_work()
        {
            TMConfig.Current    = new TMConfig();
            TM_UserData.Current = new TM_UserData();        // the fix is now here

            Action<Guid,string, string, string> checkHashValues =
                (id, username, password, hash) =>
                    {
                         var tmUser = new TMUser { ID = id, UserName = username};

                         tmUser.createPasswordHash(password)
                               .assert_Is         (hash);
                    };

            checkHashValues("8da99a4e-b15e-46d5-a732-f7b2543d4e0f".guid(),
                            "admin",
                            "!!tmadmin",
                            "OKrlvzFvi50y0JPZJJZJfKM4qDU3KFfDXgUIZysHz7Mh3jI8WwpWvnBFcRXJcWYhscZOHjIAyUHS8b1ruXP4Xg==");

            checkHashValues("d8aac161-0e25-426c-b21c-9cd230be7dba".guid(),
                            "admin",
                            "!!tmadmin",
                            "8jesPsP9ExGeoMe/NezXqh7RWQTdawsUb0znfo6VgD46nRIbAXbcgaPYCRlfLYQK1IeQphESxjZ5EDc/ZD0yFw==");

            checkHashValues("403b1277-6a78-42b7-aaa2-75a985de323a".guid(),
                            "admin",
                            "!!tmadmin",
                            "7bqGsnUsst2j/rKl6/EUg0SOLX4DpKdVdfrCjeihffP/wFKqIizWTCBpuwAO0m118fpatwrZ7RhvJPAc6PJYTA==");
        }
Exemplo n.º 2
0
 public static bool          setUserPassword(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword)
 {
     //var tmUser = tmAuthentication.currentUser;
     if (tmUser.notNull())
     {
         if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value
         {
             var newPasswordHash = tmUser.createPasswordHash(newPassword);
             if (newPasswordHash != tmUser.SecretData.PasswordHash)                        // check that password are not repeated
             {
                 tmUser.logUserActivity("User Password Change", "With previous password provided");
                 return(tmUser.setPasswordHash(newPasswordHash));
             }
         }
     }
     return(false);
 }
Exemplo n.º 3
0
 public static bool          setPassword(this TMUser tmUser, string password)
 {
     if (tmUser.isNull() || password.notValid())
     {
         return(false);
     }
     tmUser.logUserActivity("Password Change", "Direct change (by an admin)");
     return(setPasswordHash(tmUser, tmUser.createPasswordHash(password)));
 }
Exemplo n.º 4
0
 public static ChangePassword_Result setUserPasswordResponse(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword)
 {
     //var tmUser = tmAuthentication.currentUser;
     if (tmUser.notNull())
     {
         if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value
         {
             var newPasswordHash = tmUser.createPasswordHash(newPassword);
             if (newPasswordHash != tmUser.SecretData.PasswordHash) // check that password are not repeated
             {
                 tmUser.logUserActivity("User Password Change", "With previous password provided");
                 if (newPassword.Length < 8 || newPassword.Length > 256)
                 {
                     return(ValidatePasswordLength());
                 }
                 //Password Complexity chechek
                 if (!Regex.IsMatch(newPassword, ValidationRegex.PasswordComplexity))
                 {
                     tmUser.logUserActivity("User Password Change", "Your password should be at least 8 characters long. It should have one uppercase and one lowercase letter, a number and a special character.");
                     return(ValidatePasswordComplexity());
                 }
                 var result = tmUser.setPasswordHash(newPasswordHash);
                 if (result)
                 {
                     return new ChangePassword_Result {
                                PasswordChanged = true, Message = ""
                     }
                 }
                 ;
                 return(new ChangePassword_Result {
                     PasswordChanged = false, Message = TMConsts.DEFAULT_PASSWORD_CHANGE_ERROR_MESSAGE
                 });
             }
             tmUser.logUserActivity("User Password Change", "Current Password and New Password are equals");
             return(CurrentPasswordAndNewPasswordAreEqualsResponse());
         }
         tmUser.logUserActivity("User Password Change", "Current Password does not match provided value");
         return(CurrentPasswordDoNotMatchResponse());
     }
     return(new ChangePassword_Result());
 }
 public static bool          setPassword(this TMUser tmUser, string password)
 {
     if (tmUser.notNull())
     {
         tmUser.SecretData.PasswordHash       = tmUser.createPasswordHash(password);
         tmUser.AccountStatus.PasswordExpired = false;
         tmUser.saveTmUser();
         tmUser.logUserActivity("Password Change", tmUser.UserName);
         return(true);
     }
     return(false);
 }
        public static int           newUser(this TM_UserData userData, string username, string password, string email, string firstname, string lastname, string note, string title, string company, string country, string state, int groupId)
        {
            var userId = Guid.NewGuid().hash();  //10000000.random();//10.randomNumbers().toInt();

            if (userId < 0)                      // find a .net that does this (maybe called 'invert')
            {
                userId = -userId;
            }
            "Creating new user: {0} with id {1}".debug(username, userId);

            if (groupId < 1)                                    //set default user type
            {
                groupId = 2;                                    //by default new users are of type 2 (i.e. Reader)
            }
            else
            {
                UserRole.ManageUsers.demand();  // only users with UserRole.ManageUsers should be able to create non-default users
            }
            var tmUser = new TMUser {
                UserID    = userId,
                UserName  = Encoder.XmlEncode(username),
                FirstName = Encoder.XmlEncode(firstname),
                LastName  = Encoder.XmlEncode(lastname),
                Company   = Encoder.XmlEncode(company),
                Country   = Encoder.XmlEncode(country),
                State     = Encoder.XmlEncode(state),
                GroupID   = groupId,
                Title     = Encoder.XmlEncode(title),
                EMail     = Encoder.XmlEncode(email) ?? "",
            };

            tmUser.SecretData.PasswordHash = tmUser.createPasswordHash(password);
            userData.TMUsers.Add(tmUser);

            //save it
            tmUser.email_NewUser_Welcome();
            tmUser.saveTmUser();

            return(userId);
        }
Exemplo n.º 7
0
        public static int           newUser(this TM_UserData userData, string username, string password, string email, string firstname, string lastname, string note, string title, string company, string country, string state, List <UserTag> userTags, int groupId)
        {
            var userId = Math.Abs(Guid.NewGuid().hash());

            "Creating new user: {0} with id {1}".debug(username, userId);

            if (groupId < 1)                                    //set default user type
            {
                groupId = 2;                                    //by default new users are of type 2 (i.e. Reader)
            }
            else
            {
                UserRole.ManageUsers.demand();  // only users with UserRole.ManageUsers should be able to create non-default users
            }
            var tmUser = new TMUser {
                UserID    = userId,
                UserName  = Encoder.XmlEncode(username),
                FirstName = Encoder.XmlEncode(firstname),
                LastName  = Encoder.XmlEncode(lastname),
                Company   = Encoder.XmlEncode(company),
                Country   = Encoder.XmlEncode(country),
                State     = Encoder.XmlEncode(state),
                GroupID   = groupId,
                Title     = Encoder.XmlEncode(title),
                EMail     = Encoder.XmlEncode(email) ?? "",
                UserTags  = userTags
            };

            tmUser.SecretData.PasswordHash = tmUser.createPasswordHash(password);
            userData.TMUsers.Add(tmUser);

            if (TMConfig.Current.windowsAuth().isFalse())
            {
                SendEmails.SendNewUserEmails("New user created: {0}".format(tmUser.UserName), tmUser);
            }
            tmUser.logUserActivity("New User", "");
            tmUser.saveTmUser();

            return(userId);
        }
Exemplo n.º 8
0
        public static int newUser(this TM_UserData userData, string  username, string password, string email, string firstname, string lastname, string note , string title, string company, string country, string state, int groupId)
        {
            var userId = Guid.NewGuid().hash();  //10000000.random();//10.randomNumbers().toInt();
            if (userId < 0)						// find a .net that does this (maybe called 'invert')
                userId = -userId;
            "Creating new user: {0} with id {1}".debug(username, userId);

            if (groupId <1)						//set default user type
                groupId = 2;					//by default new users are of type 2 (i.e. Reader)
            else
                UserRole.ManageUsers.demand();	// only users with UserRole.ManageUsers should be able to create non-default users

            var tmUser = new TMUser {
                UserID 		 = userId,
                UserName 	 = Encoder.XmlEncode(username),
                FirstName 	 = Encoder.XmlEncode(firstname),
                LastName 	 = Encoder.XmlEncode(lastname),
                Company 	 = Encoder.XmlEncode(company),
                Country 	 = Encoder.XmlEncode(country),
                State 	     = Encoder.XmlEncode(state),
                GroupID 	 = groupId,
                Title 		 = Encoder.XmlEncode(title),
                EMail 		 = Encoder.XmlEncode(email) ?? "",
            };
            tmUser.SecretData.PasswordHash = tmUser.createPasswordHash(password);
            userData.TMUsers.Add(tmUser);

            //save it
            tmUser.email_NewUser_Welcome();
            tmUser.saveTmUser();

            return userId;
        }
Exemplo n.º 9
0
 public static ChangePassword_Result setUserPasswordResponse(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword)
 {
     //var tmUser = tmAuthentication.currentUser;
     if (tmUser.notNull())
     {
         if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value
         {
             var newPasswordHash = tmUser.createPasswordHash(newPassword);
             if (newPasswordHash != tmUser.SecretData.PasswordHash) // check that password are not repeated
             {
                 tmUser.logUserActivity("User Password Change", "With previous password provided");
                 if (newPassword.Length < 8 || newPassword.Length > 256)
                 {
                     return ValidatePasswordLength();
                 }
                 //Password Complexity chechek
                 if (!Regex.IsMatch(newPassword, ValidationRegex.PasswordComplexity))
                 {
                     tmUser.logUserActivity("User Password Change", "Your password should be at least 8 characters long. It should have one uppercase and one lowercase letter, a number and a special character.");
                     return ValidatePasswordComplexity();
                 }
                 var result = tmUser.setPasswordHash(newPasswordHash);
                 if (result)
                     return new ChangePassword_Result {PasswordChanged = true, Message = ""};
                 return new ChangePassword_Result { PasswordChanged = false, Message = TMConsts.DEFAULT_PASSWORD_CHANGE_ERROR_MESSAGE };
             }
             tmUser.logUserActivity("User Password Change", "Current Password and New Password are equals");
             return CurrentPasswordAndNewPasswordAreEqualsResponse();
         }
         tmUser.logUserActivity("User Password Change", "Current Password does not match provided value");
         return CurrentPasswordDoNotMatchResponse();
     }
     return new ChangePassword_Result();
 }
Exemplo n.º 10
0
 public static bool setUserPassword(this TM_UserData userData, TMUser tmUser, string currentPassword, string newPassword)
 {
     //var tmUser = tmAuthentication.currentUser;
     if (tmUser.notNull())
     {
         if (tmUser.SecretData.PasswordHash == tmUser.createPasswordHash(currentPassword)) // check if current password matches provided value
         {
             var newPasswordHash =  tmUser.createPasswordHash(newPassword);
             if (newPasswordHash != tmUser.SecretData.PasswordHash)                        // check that password are not repeated
             {
                 tmUser.logUserActivity("User Password Change", "With previous password provided");
                 return tmUser.setPasswordHash(newPasswordHash);
             }
         }
     }
     return false;
 }
Exemplo n.º 11
0
        public static int newUser(this TM_UserData userData, string  username, string password, string email, string firstname, string lastname, string note , string title, string company, string country, string state, List<UserTag> userTags , int groupId)
        {
            if (userData.isNull())
                return -1;

            var userId = Math.Abs(Guid.NewGuid().hash());

            "Creating new user: {0} with id {1}".debug(username, userId);

            if (groupId <1)						//set default user type
                groupId = 2;					//by default new users are of type 2 (i.e. Reader)
            else
                UserRole.ManageUsers.demand();	// only users with UserRole.ManageUsers should be able to create non-default users

            var tmUser = new TMUser {
                UserID 		 = userId,
                UserName 	 = username,
                FirstName 	 = firstname,
                LastName 	 = lastname,
                Company 	 = (company),
                Country 	 = country,
                State 	     = state,
                GroupID 	 = groupId,
                Title 		 = title,
                EMail 		 = email ?? "",
                UserTags     = userTags
            };

            var tmConfig = TMConfig.Current;
            tmUser.AccountStatus.UserEnabled    = tmConfig.newAccountsEnabled();
            tmUser.AccountStatus.ExpirationDate = tmConfig.currentExpirationDate();

            tmUser.SecretData.PasswordHash = tmUser.createPasswordHash(password);
            userData.TMUsers.Add(tmUser);

            if (TMConfig.Current.windowsAuthentication_Enabled().isFalse())
                SendEmails.SendNewUserEmails("New user created: {0}".format(tmUser.UserName), tmUser);

            tmUser.logUserActivity("New User",  "");    // this will trigger tmUser.event_User_Updated();

            //tmUser.event_User_Updated(); //tmUser.saveTmUser();
            //userData.triggerGitCommit();
            return userId;
        }