SA-MP Forums Archive
Two login problems =/ - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Two login problems =/ (/showthread.php?tid=92771)



Two login problems =/ - Badger(new) - 22.08.2009

Well I have this with strcmp which I have in two different places. For some reason, when it compaires the strings, it says that they are wrong, when (using format and SendClientMessage), I can see them being the same.

The first is for an auto login using their IP:

pawn Код:
new data[128],tmppass[128];
    GetPlayerIp(playerid,PINFO[playerid][IP],20);//Saves their IP to PINFO[playerid][IP]
    new File:PFILE=fopen(string,io_read);//Opens their saved file (string is already formatted to the location)
    format(string,sizeof(string),"%s",PINFO[playerid][IP]);// Formats string to being their IP
    while(fread(PFILE,data,128)) //Reads their file
    {
      if(strfind(data,"Password=",true)!=-1)strmid(tmppass,data,strfind(data,"=",true)+1,strlen(data));// Finds and correctly saves their password to tmppass (used for login)
      if(strfind(data,string,true)!=-1)OnPlayerLogin(playerid,tmppass);//tries to find their IP in the file, if found (not not found) logs in with tmppass
    }
The above does correctly find the saved password, IP and it does go to log them in, but in the OnPlayerLogin (modified version of sief's), it returns as saying the password is wrong.



Now the next one logs them into their account when they have a different name. I only set it to give them their admin level, it finds their admin level, file, saved password and the password they typed correctly, but when comparing the password they typed and the one from the file, it says they are not the same:

pawn Код:
while(fread(PFILE,PDATA,128))//Reads their file
  {
    if(strfind(PDATA,"Password=",true)==0)strmid(tmppass,PDATA,strfind(PDATA,"=",true)+1,strlen(PDATA));//Finds their password, saves to tmppass
    if(strfind(PDATA,"Admin=",true)==0){// Finds their admin level
      tmpadm=strval(PDATA[6]);//saves their admin level to tmpadm
      if(tmpadm<6)return SendClientMessage(playerid,ORANGE,"This is a Level 6 or above Admin command! You do not have the required admin level.");
      //finds if they don't have high enough admin level
    }
  }
  fclose(PFILE);
  tmp = strtok(cmdtext, idx);
  if(strlen(tmp)==0)return SendClientMessage(playerid,GREY,"**(E)** You haven't typed all of the command! Type: (/GLogin (AccountName) (Password)).");
  if(strcmp(tmppass,tmp,true)==0){//compairs the password typed and the one saved (both the same, yet it says they aren't)
    PINFO[playerid][Adminlvl]=tmpadm;//sets admin level
    PINFO[playerid][Global]=1;
  }
Why does the auto login end up with the right saved password but then when it's used to log them in, is said to be the wrong password?

And why does the strcmp return that the password typed and the one saved aren't the same?


Re: Two login problems =/ - Joe Staff - 22.08.2009

When a file goes to the next line it uses "\n". This counts as a character when using strmid or format. So your string, 'tmppass' is actually coming out to be something like this, "mypassword\n" Although, please note that '\n' is only 1 character, not 2. Also, in your strcmp change the 'true' to 'false' because you want the password to be case sensitive. That way "MyPassword" isn't the same as "mYpAsSwOrD"


Re: Two login problems =/ - Badger(new) - 22.08.2009

Well the second problem was fixed when, as you said, I changed
pawn Код:
if(strfind(PDATA,"Password=",true)==0)strmid(tmppass,PDATA,strfind(PDATA,"=",true)+1,strlen(PDATA));
to

pawn Код:
if(strfind(PDATA,"Password=",true)==0)strmid(tmppass,PDATA,strfind(PDATA,"=",true)+1,strlen(PDATA)-1);
I'll try fix the first one when I get back from holiday.