crypt() und verständis Problem



  • "When verifying an existing encrypted string you should
    use the encrypted text as the salt with the plaintext."
    
    So habe ich das mal versucht zu coden, Problem ist nur das ich immer den Wert 1 von der zurueckbekomme. Wieso, was stimmt am code Beispiel nicht?
    
    #ifdef AUTH_DES
    	#define AUTH_CUSR "g8WR1KAibCirI"
    	#define AUTH_CPWD "c4y9sZ1SuSbVU"
    
    	unsigned int RemoteAuthDES(char *, char *);
    #endif
    
    #ifdef AUTH_DES
    unsigned int RemoteAuthDES(char *authUser, char *authPass)
    {
    	char *username;
    	char *password;
    	static unsigned int NegAttemptsFlag = 0;
    
    	username = crypt(authUser, "g8WR1KAibCirI");
    	printf("User: %s\n", username);
    
    	password = crypt(authPass, "c4y9sZ1SuSbVU");
    	printf("Pass: %s\n", password);
    
    	if(strcmp(AUTH_CUSR, username) == 0 &&
    		strcmp(AUTH_CPWD, password) == 0)
    	{
    		return 0;
    	}
    	else
    	{
    		NegAttemptsFlag++;
    		if(NegAttemptsFlag == LOGIN_ATTEMPTS)
    		{
    			exit(1);
    		}
    		else
    		{
    			return 1;
    		}
    	}
    }
    #endif
    


  • Hallo,

    aeh, Fehlt da nicht was? Ist AUTH_DES überhaupt definiert? Wieso benutzt du überhaupt #defines? Wo ist die crypt() Funktion?



  • erstens welche AUTH_DES?
    zweitens die crypt ist doch im code?! 😉

    $ man crypt

    #define _XOPEN_SOURCE
    #include <unistd.h>
    char *crypt(const char *key, const char *salt);

    Die sind natürlich eingebunden...



  • if(strcmp(AUTH_CUSR, username) == 0 &&
            strcmp(AUTH_CPWD, password) == 0)
    

    die bedingung wird offensichtlich nicht erfüllt.. ?!
    username und AUTH_CUSR bzw password und AUTHCPWD sind auch nicht gleich..

    und apropos manpage.. da steht auch:

    salt is a two-character string chosen from the set [a-zA-Z0-9./].



  • Ja, aber ich habe mich nun daher gerichtet:

    "When verifying an existing encrypted string you should
    use the encrypted text as the salt with the plaintext."

    Wie kann ich dann denn das vorgehen anders lösen?



  • probier mal das:
    strcmp(crypt(plainPass, AUTH_xxx),AUTH_xxx)==0


Anmelden zum Antworten