コード例 #1
0
ファイル: pure-pw.c プロジェクト: jhoblitt/pure-ftpd-old
static char *best_crypt(const char * const pwd)
{
    static const char crcars[64] =
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
    const char *crypted;
    
    if ((crypted = (const char *)      /* Blowfish */
         crypt("test", "$2a$07$1234567890123456789012")) != NULL &&        
        strcmp(crypted, "$2a$07$123456789012345678901uKO4"
               "/IReKqBzRzT6YaajGvw20UBdHW7m") == 0) {
        char salt[] = "$2a$07$0000000000000000000000";        
        int c = 28;
        
        do {            
            c--;
            salt[c] = crcars[pw_zrand() & 63];
        } while (c > 7);
        
        return (char *) crypt(pwd, salt);        
    } else if ((crypted = (const char *)    /* MD5 */
                crypt("test", "$1$12345678$")) != NULL &&
               strcmp(crypted, "$1$12345678$oEitTZYQtRHfNGmsFvTBA/") == 0) {
        char salt[] = "$1$00000000";
        int c = 10;
        
        do {            
            c--;
            salt[c] = crcars[pw_zrand() & 63];
        } while (c > 3);
        
        return (char *) crypt(pwd, salt);
    } else if ((crypted = (const char *)    /* Extended DES */
                crypt("test", "_.../1234")) != NULL &&
               strcmp(crypted, "_.../1234PAPUVmqGzpU") == 0) {
        char salt[] = "_.../0000";
        int c = 8;
        
        do {
            c--;
            salt[c] = crcars[pw_zrand() & 63];
        } while (c > 5);
        
        return (char *) crypt(pwd, salt);
    }
    /* Simple DES */
    {
        char salt[] = "00";
        
        salt[0] = crcars[pw_zrand() & 63];
        salt[1] = crcars[pw_zrand() & 63];
        
        return (char *) crypt(pwd, salt);        
    }    
}
コード例 #2
0
static char *best_crypt(const char * const pwd)
{
    static const char crcars[64] =
        "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
    const char *crypted;

    if ((crypted = (const char *)      /* Blowfish */
         crypt("test", "$2a$08$1234567890123456789012")) != NULL &&
        strcmp(crypted,
               "$2a$08$123456789012345678901uBdmsfIXjJcWQwz1wT/IZrWhimJ6xy6a")
        == 0) {
        char salt[] = "$2a$08$0000000000000000000000";
        int c = 28;
        
        do {            
            c--;
            salt[c] = crcars[pw_zrand() & 63];
        } while (c > 7);
        
        return (char *) crypt(pwd, salt);        
    } else if ((crypted = (const char *)    /* SHA-512 */
                crypt("test", "$6$1234567890123456$")) != NULL &&
               strcmp(crypted,
                      "$6$1234567890123456$d.pgKQFaiD8bRiExg5NesbGR/"
                      "3u51YvxeYaQXPzx4C6oSYREw8VoReiuYZjx0V9OhGVTZF"
                      "qhc6emAxT1RC5BV.") == 0) {
        char salt[] = "$6$0000000000000000";
        int c = 18;

        do {
            c--;
            salt[c] = crcars[pw_zrand() & 63];
        } while (c > 3);

        return (char *) crypt(pwd, salt);
    } else if ((crypted = (const char *)    /* MD5 */
                crypt("test", "$1$12345678$")) != NULL &&
               strcmp(crypted, "$1$12345678$oEitTZYQtRHfNGmsFvTBA/") == 0) {
        char salt[] = "$1$00000000";
        int c = 10;
        
        do {            
            c--;
            salt[c] = crcars[pw_zrand() & 63];
        } while (c > 3);
        
        return (char *) crypt(pwd, salt);
    } else if ((crypted = (const char *)    /* Extended DES */
                crypt("test", "_.../1234")) != NULL &&
               strcmp(crypted, "_.../1234PAPUVmqGzpU") == 0) {
        char salt[] = "_.../0000";
        int c = 8;
        
        do {
            c--;
            salt[c] = crcars[pw_zrand() & 63];
        } while (c > 5);
        
        return (char *) crypt(pwd, salt);
    }
    /* Simple DES */
    {
        char salt[] = "00";
        
        salt[0] = crcars[pw_zrand() & 63];
        salt[1] = crcars[pw_zrand() & 63];
        
        return (char *) crypt(pwd, salt);        
    }    
}