Trim passwords, is it wrong?

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?

+4
source share
6 answers

You cannot store passwords in plain text.

+12
source

, , , , , ... , String.IsNullOrWhiteSpace, , ,

+3

, .

, . , , , ( cut/paste ). , , / - .

, , , , . , - , . , "" , , , , .

+2

. .

, SecureString String .

+1

I suggest that you set a minimum character limit or check that the password is valid, and not truncate.

+1
source

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*
+1
source

All Articles