I have a script that saves and loads a .data file... but it doesn't seem to work properly.. Cause as i press login it says the password is wrong and even if i enter the correct password... Code (csharp): if(load == true) { if(File.Exists(path + enteredUsername + ".data")) { using(FileStream fs = File.OpenRead(path + enteredUsername + ".data")) { byte[] b = new byte[1024]; UTF8Encoding temp = new UTF8Encoding(true); while(fs.Read(b,0,b.Length) > 0) { tempPassword = temp.GetString(b); } if(enteredPassword == tempPassword) { LoggedIn(); } else { lastMessage = "Wrong password!"; load = false; } } } else { lastMessage = "This account doesn't excist in our database!"; } }
Just a wild crack for brainstorming purposes - this may be way off base, but is "path" set anywhere? Code (csharp): using(FileStream fs = File.OpenRead(path + enteredUsername + ".data")) { If not, this: Code (csharp): while(fs.Read(b,0,b.Length) > 0) { tempPassword = temp.GetString(b); } would never set "tempPassword", which would cause this: Code (csharp): if(enteredPassword == tempPassword) { LoggedIn(); } to always be not true.
No the path is alright, cause when i save the file trough script it saves correctly into correct folder,
Logging seemed to help a little, now i know that the tempPassword is what it should be but the script just stops after loading the file... Maybe i'll try to call a function where it sets the tempPassword...
Do you have the enteredPassword password at this point in the script, and is it the proper type? You seem to have verified the tempPassword. If you know that is correct, check and see what you are comparing it against. (enteredPassword). Toss in a debug before the comparison to output what enteredPassword is and its type. You might also double check that you aren't getting white space that is causing the false result. I have ran into that before, and since it does really appear in the debug log, I looking other places. In other words "foo" != "foo ". Good luck! ZG
Well, i just debugged both like this Code (csharp): Debug.Log("1st: " + tempPassword + "....."); Debug.Log("2nd: " + enteredPassword + "....."); but the console shows 1st: 2 UnityEngine.Debug:Log(Object) Networking:OnGUI() (at Assets/__GData/Scripts/Network/Networking.cs:56) 2nd: 2..... UnityEngine.Debug:Log(Object) Networking:OnGUI() (at Assets/__GData/Scripts/Network/Networking.cs:57) there's something wrong with tempPassword?
Fixed this, thanks to all of you, I've finally figured it out. the problem was that when I opened the file it was making the password 1024 characters long so, just replaced: byte[] b = new byte[1024]; with this: byte[] b = new byte[enteredPassword.Length];