[EP2]Register Script [PHP]

11/07/2012 02:52 Sentence'#1
Da ich zu faul war jedesmal manuell alles in die DB einzutragen hab ich mir schnell ein script gebastelt^^

#gelöscht

Credits :
- FapMax (clean_str funktion)

So viel Spaß damit^^
11/07/2012 12:02 Samker#2
Hey sel ähm ich glaube das script wird gut buggen da mysql real escape string eine mysql verbindung braucht wenn ich mich recht erinnere aber egal warum prüfst du ein passwort auf sqli was sowieso erst verschlüsselt wird bevor es an die datenbank kommt ? o.O und "htmlspecialchars" brauchst du nach clean_str eh nichtmehr weil nach cleanstr nurnoch a-z, A-Z, 0-9 und "@ und ." übrig bleibt ?

Aber sonst gute arbeit ich wette das hätte nicht viele aus der sektion hinbekommen. Gut ich gebs zu ich glaube fast keiner

Mfg Samker
11/07/2012 14:38 €clips3#3
Quote:
Originally Posted by Samker View Post
Hey sel ähm ich glaube das script wird gut buggen da mysql real escape string eine mysql verbindung braucht wenn ich mich recht erinnere aber egal warum prüfst du ein passwort auf sqli was sowieso erst verschlüsselt wird bevor es an die datenbank kommt ? o.O und "htmlspecialchars" brauchst du nach clean_str eh nichtmehr weil nach cleanstr nurnoch a-z, A-Z, 0-9 und "@ und ." übrig bleibt ?

Aber sonst gute arbeit ich wette das hätte nicht viele aus der sektion hinbekommen. Gut ich gebs zu ich glaube fast keiner

Mfg Samker
Sicher keiner.
11/07/2012 14:40 SânSalvador#4
Quote:
Originally Posted by PapiSchlumpf View Post
Sicher keiner.
Ein paar bestimmt schon ;)
11/07/2012 14:42 Samker#5
Quote:
Originally Posted by SânSalvador View Post
Ein paar bestimmt schon ;)
also sel tefarian basti180 hateme fapmax ich das ist keine frage aber sonst eigentlich keiner gut wizatek MaX (bin ich mir nicht sicher :D) und ein paar wenige mehr
11/07/2012 15:03 Sentence'#6
Quote:
Originally Posted by Samker View Post
Hey sel ähm ich glaube das script wird gut buggen da mysql real escape string eine mysql verbindung braucht wenn ich mich recht erinnere aber egal warum prüfst du ein passwort auf sqli was sowieso erst verschlüsselt wird bevor es an die datenbank kommt ? o.O und "htmlspecialchars" brauchst du nach clean_str eh nichtmehr weil nach cleanstr nurnoch a-z, A-Z, 0-9 und "@ und ." übrig bleibt ?

Aber sonst gute arbeit ich wette das hätte nicht viele aus der sektion hinbekommen. Gut ich gebs zu ich glaube fast keiner

Mfg Samker
Weil ich das Script im Halbschlaf geschrieben habe, also habe ich einfach alles an Sicherheitsprüfung reingehauen was es gibt D:
11/07/2012 16:27 illyminati#7
Quote:
Originally Posted by Samker View Post
also sel tefarian basti180 hateme fapmax ich das ist keine frage aber sonst eigentlich keiner gut wizatek MaX (bin ich mir nicht sicher :D) und ein paar wenige mehr
du lügst, vergiss nicht whazzert!
11/07/2012 16:49 Samker#8
Quote:
Originally Posted by illyminati View Post
du lügst, vergiss nicht whazzert!
ich habe keine ahnung bist du einfach nur strunz dumm oder soll das ironie sein wirklich ich habe keine ahnung es gibt zu viele in der sektion denen ich so viel dummheit zutraue
11/07/2012 17:30 Wizatek#9
I can understand that u want to clean the username, but why are u cleaning the password? A good password consists out of atleast a few special chars also :@&$*(; etc, etc.

the mysql_real_escape_string will do nothing in this context btw.
It is to be used with the mysql_ library and not the mysqli because it uses its own sanitizing functions.

Do some more research on mysqli prepared statements, then u are 100% sure u are safe.
11/07/2012 17:32 Tarissuis#10
Kommen da auch so beleidigende Meldungen wie bei deinen restlichen Tools, so nach dem Motto "Dein Account wurde angelegt du reallifesloses kleinen Stück *censored*"?

11/07/2012 17:36 Wizatek#11
PHP Code:
<?php

    
if( isset( $_POST['username'] ) && !empty( $_POST['username'] ) && isset( $_POST['password'] ) && !empty( $_POST['password'] ))
    {

        
$conf['db']['server'] = '123.456.789.123';
        
$conf['db']['user'] = 'mysql_username_here';
        
$conf['db']['pass'] = 'mysql_assword_here';
        
        
$conf['dbname']['auth'] = 'newproject_auth';
        
        
$salt 'salt_here';
        
        
// Create the DSN
        
$conf['db']['dsn'] = sprintf("mysql:host=%s;dbname=%s"$conf['db']['server'], $conf['dbname']['auth'] );
        
        
        
// Try to connect to the database
        
try 
        {
            
$db = new PDO($conf['db']['dsn'], $conf['db']['user'], $conf['db']['pass']);
        } 
        catch(
PDOException $e)
        {
            die(
'Error connecting to the database<br />');
        }
        
        
        
$dbh $db->prepare("SELECT count(*) FROM bg_user WHERE user_id = :user");
        
$dbh->execute( array( ':user' => $_POST['username'] ));
        
        
$result $dbh->fetch();
        
        if( 
$result[0] != )
            echo 
'User 'htmlspecialchars$_POST['username'] ) .' already exist';
        else
        {
            
            
$hash hash('sha256'$_POST['username'] . $salt $_POST['password']);
            
            
$dbh $db->prepare("INSERT INTO bg_user (user_id, passwd) VALUES(:user,:pass)");
            
$dbh->execute( array( ':user' => $_POST['username'],
                                  
':pass' => $hash ));
            
            echo 
'['htmlspecialchars$_POST['username'] ) .'] Account created!<hr />';
        
        }
        

    }
    else
    {

        echo 
'
            <form method="post">
                <table>
                    <tr>
                        <td>Username</td>
                        <td><input type="text" name="username" size="30" maxlength="16" /></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td><input type="text" name="password" size="30" /></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" value="Create account" /></td>
                    </tr>
                </table>
            </form>'
;
    }

?>
11/07/2012 17:46 Samker#12
Quote:
Originally Posted by wizatek View Post
PHP Code:
<?php

    
if( isset( $_POST['username'] ) && !empty( $_POST['username'] ) && isset( $_POST['password'] ) && !empty( $_POST['password'] ))
    {

        
$conf['db']['server'] = '123.456.789.123';
        
$conf['db']['user'] = 'mysql_username_here';
        
$conf['db']['pass'] = 'mysql_assword_here';
        
        
$conf['dbname']['auth'] = 'newproject_auth';
        
        
$salt 'salt_here';
        
        
// Create the DSN
        
$conf['db']['dsn'] = sprintf("mysql:host=%s;dbname=%s"$conf['db']['server'], $conf['dbname']['auth'] );
        
        
        
// Try to connect to the database
        
try 
        {
            
$db = new PDO($conf['db']['dsn'], $conf['db']['user'], $conf['db']['pass']);
        } 
        catch(
PDOException $e)
        {
            die(
'Error connecting to the database<br />');
        }
        
        
        
$dbh $db->prepare("SELECT count(*) FROM bg_user WHERE user_id = :user");
        
$dbh->execute( array( ':user' => $_POST['username'] ));
        
        
$result $dbh->fetch();
        
        if( 
$result[0] != )
            echo 
'User 'htmlspecialchars$_POST['username'] ) .' already exist';
        else
        {
            
            
$hash hash('sha256'$_POST['username'] . $salt $_POST['password']);
            
            
$dbh $db->prepare("INSERT INTO bg_user (user_id, passwd) VALUES(:user,:pass)");
            
$dbh->execute( array( ':user' => $_POST['username'],
                                  
':pass' => $hash ));
            
            echo 
'['htmlspecialchars$_POST['username'] ) .'] Account created!<hr />';
        
        }
        

    }
    else
    {

        echo 
'
            <form method="post">
                <table>
                    <tr>
                        <td>Username</td>
                        <td><input type="text" name="username" size="30" maxlength="16" /></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td><input type="text" name="password" size="30" /></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" value="Create account" /></td>
                    </tr>
                </table>
            </form>'
;
    }

?>
Wizatek a little tipp set the pdo charset to UTF-8 then you can input all sysmbols but the clean_str function from fapmax delete all these
11/07/2012 17:46 Sentence'#13
Quote:
Originally Posted by wizatek View Post
I can understand that u want to clean the username, but why are u cleaning the password? A good password consists out of atleast a few special chars also :@&$*(; etc, etc.

the mysql_real_escape_string will do nothing in this context btw.
It is to be used with the mysql_ library and not the mysqli because it uses its own sanitizing functions.

Do some more research on mysqli prepared statements, then u are 100% sure u are safe.
I was really tired at the time I was scripting this, but it works. :D
11/07/2012 17:50 Samker#14
Quote:
Originally Posted by Sentence' View Post
I was really tired at the time I was scripting this, but it works. :D
yeah i just say the same thing but i have my answer via skype
11/08/2012 14:14 IchVerabschiedeMich#15
Das Script ist Grotten schlecht Coded.