Checking if a Password exists

Hi I’m trying to create a Login menu with Input Fields. I have a Username and a Password field. The Password is encrypted before with a Sign Up Menu.

The problem is that the password is not being recognized in the Login Menu. I keep getting the Debug (“Password Invalid”). The code below is how it is interpreting the existing password for the user. But I’m not really sure why it’s not working.

The Lines array has a Username, Email and Password (hence the [2])

Also, all these txt files are being saved in the Unity Project folder so there isn’t a set folder path I’ve sent the information to yet.

Any ideas would be great, thanks!

if (Password != "") 
	{

		if (System.IO.File.Exists (@Username + ".txt")) 
		{
			int i = 1;

			foreach (char c in Lines[2]) 
			{
				i++;
				char Decrypted = (char)(c / i);
				DecryptedPass += Decrypted.ToString();
			}

			if (Password == DecryptedPass) 
			{
				boolPass = true;
			}

			else 
			{
				Debug.LogWarning ("Password Invalid");
				passwordText.text = "Password Not Correct";
			}

		}

Well, have you actually start debugging the problem? Are you sure that your method of “encrypting” can actually be reverted? What you do is quite dangerous. You can easily end up with illegal character combinations which might not be able to be stored proberly.

Another reason might be that your source string contains additional characters like a new line character.

Usually you would do something like this:

Debug.Log("EnteredPassword: >" + Password + "< Length: " + Password.Length );
Debug.Log("DecryptedPassword: >" + DecryptedPass + "< Length: " + DecryptedPass.Length );

right before your if (Password == DecryptedPass) line.

Are you sure that lines[2] is correct? Keep in mind that is the 3rd line. (just read that this is correct, or at least should be correct).

As bunny said, salted hashes are really the only way you should do this. This Compterphile video should explain why.