I had a problem that the password for the new entry was not empty, it was an empty space. So, the first thing that came to mind was to call Trim()where I upload or save passwords, so it will no longer have this gap. But I wanted to know your opinion about whether this will be wrong or not?
Trim()
You cannot store passwords in plain text.
, , , , , ... , String.IsNullOrWhiteSpace, , ,
, .
, . , , , ( cut/paste ). , , / - .
, , , , . , - , . , "" , , , , .
. .
, SecureString String .
I suggest that you set a minimum character limit or check that the password is valid, and not truncate.
The correct behavior (at least one of the best practices) is to try to encrypt and then hash passwords. Encryption of even the simplest password, even a simple space will create a line without spaces.
Here is a simple code for this:
public static string Hash(this string text) { HashAlgorithm algorithm = algorithm = MD5.Create(); ; // Adding something (salt) to text to make it harder to guess text += "some-salt"; //return algorithm.ComputeHash(text.ToBytes()).GetString().ToBase64(); return Encoding.UTF8.GetString(algorithm.ComputeHash(Encoding.UTF8.GetBytes(text))); }
Call this function in a space, and the result:
var result = " ".Hash(); // Xd m SJ l|r Z*