AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Help compare two strings (https://forums.alliedmods.net/showthread.php?t=313926)

TudorLaLeagane 01-28-2019 09:19

Help compare two strings
 
Hi! I would like to compare two strings. Here is my code:

PHP Code:

stock LogInUser(id,givenpass[65])
{
    if(
gLoggedin[id] == 0){
        new 
userid get_user_userid(id)  
        
log_amx("%s - gpass || %s - user pass",givenpass,gPassword[id])
        if(
strcmp(gPassword[id],givenpass) == 0)
        {
            
chat_color(id,"!y[!gDR!y]!g Te-ai logat cu succes!")
            
gLoggedin[id] = 1
        
}
        else{
            
server_cmd("kick #%d parola incorecta!",userid)
        }
    }
    else{
        
chat_color(id,"!y[!gDR!y]!g Esti deja logat!")
        return 
PLUGIN_CONTINUE
    
}
    return 
PLUGIN_CONTINUE


In real life, givenpass = 1234
gPassword[id] = 1234
It takes the password from a file, here is the code for that:
PHP Code:

public LoadData(id){
    if(
is_user_bot(id))
    {
        return 
PLUGIN_HANDLED
    
}
    new 
Name[33]
    
get_user_name(id,Name,charsmax(Name))
    new 
path[128]
    
format(path,127,"%s%s.txt",gPathMaster,Name)
    if(!
file_exists(path))
    {
      
write_file(path,"PAROLA:",4)
    }
    new 
fopen(path,"r")
    new 
szLine[128]
    while(!
feof(f))
    {
        
fgets(f,szLine,charsmax(szLine))
        if(
contain(szLine,"PAROLA:") >-)
        {
            
replace_all(szLine,127,"PAROLA:","")
            
format(gPassword[id],64,"%s",szLine)
            
CheckPassword(id)
        }
    }
    if(
Credite[id] == 0)
    {
        
Credite[id] = 500000
    
}
    
fclose(f)
    return 
PLUGIN_HANDLED


Even tho the strings are completly the same, it still says that they are different.

CrazY. 01-28-2019 09:22

Re: Help compare two strings
 
equal or equali.

TudorLaLeagane 01-28-2019 09:30

Re: Help compare two strings
 
It's the same output... The password is incorrect.
PHP Code:

 if(equal(gPassword[id],givenpass,64)) 


eat1k 01-28-2019 10:00

Re: Help compare two strings
 
remove_quotes/trim.

CrazY. 01-28-2019 10:22

Re: Help compare two strings
 
Also debug passwords.

TudorLaLeagane 01-28-2019 11:16

Re: Help compare two strings
 
Quote:

Originally Posted by CrazY. (Post 2636985)
Also debug passwords.

I had it debug...

But it works with Trim, so thank you all <3


All times are GMT -4. The time now is 07:31.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.