이전 개발자가 작성한 시스템을 인계받습니다. 시스템에 관리자가 사용자 계정을 승인하면 시스템에서 암호를 해시하고 데이터베이스에 저장하기 위해 다음 방법을 사용합니다. 그것은 해킹되지 않은 암호를 사용자에게 전송합니다. 사용자가 로그인 할 때 시스템은 똑같은 방법을 사용하여 사용자가 입력 한 것을 해시하고 데이터베이스 값과 비교합니다. 데이터베이스 항목이 사용자 유치 항목과 일치하지 않을 때 몇 번 실행되었습니다. 그래서이 방법은 항상 같은 값을 해시하지 않는 것으로 보입니다. 누구든지이 해싱 방법이 신뢰할 수없고 어떻게 신뢰할 수 있는지 알고 있습니까? 감사. 절차 (즉, 완전히 결정이다), 그리고 사용되는 알고리즘의 구현이 동일 (그들이 있어야 할 임의 의사 결정을 사용하지 않는 경우해싱 패스워드가 다른 결과를 나타냄
private string HashPassword(string password)
{
string hashedPassword = string.Empty;
// Convert plain text into a byte array.
byte[] plainTextBytes = Encoding.UTF8.GetBytes(password);
// Allocate array, which will hold plain text and salt.
byte[] plainTextWithSaltBytes =
new byte[plainTextBytes.Length + SALT.Length];
// Copy plain text bytes into resulting array.
for(int i = 0; i < plainTextBytes.Length; i++)
plainTextWithSaltBytes[i] = plainTextBytes[i];
// Append salt bytes to the resulting array.
for(int i = 0; i < SALT.Length; i++)
plainTextWithSaltBytes[plainTextBytes.Length + i] = SALT[i];
// Because we support multiple hashing algorithms, we must define
// hash object as a common (abstract) base class. We will specify the
// actual hashing algorithm class later during object creation.
HashAlgorithm hash = new SHA256Managed();
// Compute hash value of our plain text with appended salt.
byte[] hashBytes = hash.ComputeHash(plainTextWithSaltBytes);
// Create array which will hold hash and original salt bytes.
byte[] hashWithSaltBytes = new byte[hashBytes.Length +
SALT.Length];
// Copy hash bytes into resulting array.
for(int i = 0; i < hashBytes.Length; i++)
hashWithSaltBytes[i] = hashBytes[i];
// Append salt bytes to the result.
for(int i = 0; i < SALT.Length; i++)
hashWithSaltBytes[hashBytes.Length + i] = SALT[i];
// Convert result into a base64-encoded string.
hashedPassword = Convert.ToBase64String(hashWithSaltBytes);
return hashedPassword;
}