/// <summary> /// This function takes a password and then /// writes the siteSecurity.config file. /// </summary> /// <param name="userName">The username of the logged in user</param> /// <param name="password">The plain text password of the logged in user</param> public static void SetPassword(string userName, string password) { SiteSecurityConfig ssc = GetSecurity(); User user = GetUser(userName); user.Password = password; // write out the changes SetSecurity(ssc); }
/// <summary> /// This function looks up a given displayname and returns the associated /// User object. /// </summary> /// <param name="userName">The displayname to look up.</param> /// <returns>The User object corresponding to the provided displayname.</returns> public static User GetUserByDisplayName(string displayName) { if (false == String.IsNullOrEmpty(displayName)) { SiteSecurityConfig ssc = GetSecurity(); return(ssc.Users.Find(delegate(User x) { return String.Compare(x.DisplayName, displayName, StringComparison.InvariantCultureIgnoreCase) == 0; })); } return(null); }
/// <summary> /// This function looks up a given email and returns the associated /// User object. /// </summary> /// <param name="userName">The email to look up.</param> /// <returns>The User object corresponding to the provided email.</returns> public static User GetUserByEmail(string email) { if (false == String.IsNullOrEmpty(email)) { SiteSecurityConfig ssc = GetSecurity(); return(ssc.Users.Find(delegate(User x) { return String.Compare(x.EmailAddress, email, StringComparison.InvariantCultureIgnoreCase) == 0; })); } return(null); }
/// <summary> /// Adds a new user to the current collection of users. /// </summary> /// <param name="user">The user to add.</param> public static void AddUser(User user) { if (user == null) { throw new ArgumentNullException("user"); } SiteSecurityConfig ssc = GetSecurity(); ssc.Users.Add(user); SetSecurity(ssc); }
/// <summary> /// Finds the user in the current user collection and replaces him with the supplied user. /// The mapping is done by the username. /// </summary> /// <param name="user">The user to update.</param> public static void UpdateUser(User user) { if (user == null) { throw new ArgumentNullException("user"); } SiteSecurityConfig ssc = GetSecurity(); int index = ssc.Users.FindIndex(delegate(User x) { return(String.Compare(x.Name, user.Name, StringComparison.InvariantCultureIgnoreCase) == 0); }); if (index >= 0) { ssc.Users[index] = user; SetSecurity(ssc); } }
/// <summary> /// This function takes a password and the userName to /// compare the password with the password asigned to the userName. /// Both passwords, only one or none will exist as md5 hashed. /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <returns>user as UserToken.</returns> public static UserToken Login(string userName, string password) { UserToken token = null; SiteSecurityConfig ssc = GetSecurity(); /* * foreach (User user in ssc.Users) * { * if (user.Name.ToUpper() == userName.ToUpper() && user.Active) * { * if ((IsCleanStringEncrypted(user.Password) && IsCleanStringEncrypted(password)) || * (!IsCleanStringEncrypted(user.Password) && !IsCleanStringEncrypted(password))) * { * if (user.Password == password) * { * token = user.ToToken(); * break; * } * else if (user.Password == SiteSecurity.Encrypt(password)) * { * token = user.ToToken(); * break; * } * } * else if ((IsCleanStringEncrypted(user.Password) && !IsCleanStringEncrypted(password))) * { * if (user.Password == Encrypt(password)) * { * token = user.ToToken(); * break; * } * } * else * { * if (Encrypt(user.Password) == password) * { * token = user.ToToken(); * break; * } * } * } * } * */ User user = GetUser(userName); if (user != null && user.Active) { //Make sure password is encrypted if (!IsCleanStringEncrypted(password)) { password = SiteSecurity.Encrypt(password); } //if the stored password is encrypted, test equality, or test equality with the encrypted version of it if ((IsCleanStringEncrypted(user.Password) && user.Password == password) || (SiteSecurity.Encrypt(user.Password) == password)) { token = user.ToToken(); } } Login(token, userName); return(token); }