public static string Generate_Identifier_Name(string Directory, string Database) { byte[] salt = { }; string Identifier = "Red_WCF_Tutorial@" + EncriptionProvider.ComputeHash(Directory + Database, EncriptionProvider.Supported_HA.SHA256, salt); return(Identifier); }
/// <summary> /// Modifies the username and/or the password of a user. /// </summary> /// <param name="oldUserID"></param> /// <param name="newUserId"></param> /// <param name="password">The encription of the password is handled by the UsersProvider.</param> /// <returns></returns> public static bool Modify(string oldUserID, string newUserId, string password) { UserEntity User = new UserEntity(newUserId, EncriptionProvider.ComputeHash(password, EncriptionProvider.Supported_HA.SHA256, null)); if (oldUserID != newUserId) { return(DeleteUser(oldUserID) && NewUser(newUserId, password)); } return(DatabaseConnection.Modify <UserEntity>(User, p => p.Username == oldUserID)); }
/// <summary> /// Checks if the username is in the database and the password parameter is matching the encripted password. /// </summary> /// <param name="userID"></param> /// <param name="pw">The encription of the password is handled by the UsersProvider.</param> /// <returns></returns> public static bool IsValidPassword(string userID, string pw) { bool exists = false; using (var db = new InventoryContext(DatabaseConnection.ConnectionString)) { var q = from u in db.Users where (u.Username == userID) select u; foreach (var user in q) { exists = exists || EncriptionProvider.Confirm(pw, user.Password, EncriptionProvider.Supported_HA.SHA256); } } return(exists); }
/// <summary> /// Adds a new user to the database /// </summary> /// <param name="userID"></param> /// <param name="password">The encription of the password is handled by the UsersProvider.</param> /// <returns></returns> public static bool NewUser(string userID, string password) { UserEntity User = new UserEntity(userID, EncriptionProvider.ComputeHash(password, EncriptionProvider.Supported_HA.SHA256, null)); return(DatabaseConnection.Add <UserEntity>(User)); }