TAILIEUCHUNG - Storing Data Securely

Phương pháp CreateHashedPassword tạo ra mật khẩu muối và băm. các mật khẩu tham số là văn bản đơn giản của mật khẩu, tham số existingSalt là muối để sử dụng khi tạo ra phiên bản muối và băm. Nếu muối không tồn tại, chẳng hạn như lần đầu tiên một mật khẩu được lưu trữ, existingSalt nên được thông qua như vô giá trị, và một ngẫu nhiên muối được tạo ra. Một khi bạn có muối, nó được kết hợp với mật khẩu đồng bằng văn bản và băm bằng cách sử dụng lớp SHA512Managed. Giá trị muối sau đó được nối thêm vào. | return return set XmlNode pwdNode Settings Password string hashedPassword CreateHashedPassword value null if pwdNode null hashedPassword else XmlNode settingsNode Settings XmlElement pwdElem Password hashedPassword pwdElem _ The CreateHashedPassword method creates the salted and hashed password. The password parameter is the plain text of the password the existingSalt parameter is the salt to use when creating the salted and hashed version. If no salt exists such as the first time a password is stored existingSalt should be passed as null and a random salt will be generated. Once you have the salt it is combined with the plain text password and hashed using the SHA512Managed class. The salt value is then appended to the end of the hashed value and returned. The salt is appended so that when you attempt to validate the password you know what salt was used to create the hashed value. The entire value is then base64-encoded and returned Make a hashed password. private string CreateHashedPassword string password byte existingSalt byte salt null if existingSalt null Make a salt of random size. Create a stronger hash code using RNGCryptoServiceProvider. byte random new byte 1 RNGCryptoServiceProvider rngSize new RNGCryptoServiceProvider Populate with random bytes. random Convert random bytes to string. Storing Data Securely 679 int size random Create salt array. salt new byte size Use the better random number generator to get bytes for the salt. RNGCryptoServiceProvider rngSalt new RNGCryptoServiceProvider salt else salt existingSalt Turn string into bytes. byte pwd password Make storage for both password and salt. byte saltedPwd new byte Add pwd bytes first. saltedPwd 0 now add salt .

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.