定義
bool ChangePassword( string userName, string oldPassword, string newPassword );
パラメーター
| 名前 | 型 | 説明 |
|---|---|---|
userName | string | ユーザー名。 |
oldPassword | string | 暗号化されていない古いパスワード。 |
newPassword | string | 新しいパスワード。 |
戻り値
| 型 | 説明 |
|---|---|
bool | パスワード がリセットされたかどうかを示します。指定可能な値は、true (パスワード が正常にリセットされた) 、false (古いパスワード が一致しないなどの理由で、パスワード がリセットされなかった) です。 |
パスワードハッシュを計算する
public static string GetPasswordHashWithSalt( string login, string password )
{
string salt = GetPasswordSha256Hash(login.ToUpper());
return GetPasswordSha256Hash(password + salt);
}
private static string GetPasswordSha256Hash( string password )
{
Encoding enc = Encoding.GetEncoding("UTF-16");
byte[] buffer = enc.GetBytes(password);
var cryptoTransformSHA256 = new SHA256CryptoServiceProvider();
string hash = BitConverter.ToString(cryptoTransformSHA256.ComputeHash(buffer)).Replace("-", "");
return hash;
}
