<commit_before><?php
    include 'encrypt.php';
    class User {
        public function exists( $username ) {
            $res = db(
                'SELECT
                    username
                FROM
                    users
                WHERE
                    username = :username
                LIMIT 1;', 
                compact( "username" ) 
            );
            if ( mysql_num_rows( $res ) == 1 ) {
                return true;
            }
            return false;
        }

        public function mailExists( $mail ) {
            $res = db(
                'SELECT
                    username
                FROM
                    users
                WHERE
                    email = :mail
                LIMIT 1;', 
                compact( "mail" ) 
            );
            if ( mysql_num_rows( $res ) == 1 ) {
                return true;
            }
            return false;
        }

        public function validMail( $mail ) {
            $posat = strrpos( $mail, "@" );
            $posdot = strrpos( $mail, "." );
            if ( $posat < 1 || $posat === false || $posdot === strlen( $mail ) || $posdot === false ) {
                return false;
            }
            return true;
        }

        public function createUser( $username, $password, $email ) {
            if ( strlen( $password ) <= 6 ) {
                throw new RedirectException( 'index.php?resource=user&method=create&small_pass=yes' );
            }
            if ( !User::validMail( $email ) ) {
                throw new RedirectException( 'index.php?mail_notvalid=yes&resource=user&method=create' );
            }
            $array = encrypt( $password );
            $password = $array[ 'hash' ];
            $salt = $array[ 'salt' ];
            db(
                'INSERT INTO
                    users
                SET
                    username = :username,
                    password = <PASSWORD>,
                    email = :email,
                    salt = :salt;',
                compact( "username", "password", "email", "salt" )
            );
            return mysql_insert_id();
        }

        public function delete( $username ) {
            db(
                'DELETE FROM
                    users
                WHERE
                    username = :username;', 
                compact( "username" )
            );
        }

        public function update( $username, $password ) {
            if ( strlen( $password ) <= 6 ) {
                throw new RedirectException( 'index.php?resource=user&method=update&small_pass=yes' );
            }
            $array = encrypt( $password );
            $password = $array[ 'hash' ];
            $salt = $array[ 'salt' ];
            db(
                'UPDATE
                    users
                SET
                    password = :password,
                    salt = :salt
                WHERE
                    username = :username',
                compact( "username", "password", "salt" )
            );
        }

        public function authenticateUser( $username, $password ) {
            $res = db(
                'SELECT
                    userid, password, salt
                FROM
                    users<commit_msg>Added LIMIT 1 for safety<commit_after><?php
    include 'encrypt.php';
    class User {
        public function exists( $username ) {
            $res = db(
                'SELECT
                    username
                FROM
                    users
                WHERE
                    username = :username
                LIMIT 1;', 
                compact( "username" ) 
            );
            if ( mysql_num_rows( $res ) == 1 ) {
                return true;
            }
            return false;
        }

        public function mailExists( $mail ) {
            $res = db(
                'SELECT
                    username
                FROM
                    users
                WHERE
                    email = :mail
                LIMIT 1;', 
                compact( "mail" ) 
            );
            if ( mysql_num_rows( $res ) == 1 ) {
                return true;
            }
            return false;
        }

        public function validMail( $mail ) {
            $posat = strrpos( $mail, "@" );
            $posdot = strrpos( $mail, "." );
            if ( $posat < 1 || $posat === false || $posdot === strlen( $mail ) || $posdot === false ) {
                return false;
            }
            return true;
        }

        public function createUser( $username, $password, $email ) {
            if ( strlen( $password ) <= 6 ) {
                throw new RedirectException( 'index.php?resource=user&method=create&small_pass=yes' );
            }
            if ( !User::validMail( $email ) ) {
                throw new RedirectException( 'index.php?mail_notvalid=yes&resource=user&method=create' );
            }
            $array = encrypt( $password );
            $password = $array[ 'hash' ];
            $salt = $array[ 'salt' ];
            db(
                'INSERT INTO
                    users
                SET
                    username = :username,
                    password = <PASSWORD>,
                    email = :email,
                    salt = :salt;',
                compact( "username", "password", "email", "salt" )
            );
            return mysql_insert_id();
        }

        public function delete( $username ) {
            db(
                'DELETE FROM
                    users
                WHERE
                    username = :username
                LIMIT 1;', 
                compact( "username" )
            );
        }

        public function update( $username, $password ) {
            if ( strlen( $password ) <= 6 ) {
                throw new RedirectException( 'index.php?resource=user&method=update&small_pass=yes' );
            }
            $array = encrypt( $password );
            $password = $array[ 'hash' ];
            $salt = $array[ 'salt' ];
            db(
                'UPDATE
                    users
                SET
                    password = <PASSWORD>,
                    salt = :salt
                WHERE
                    username = :username
                LIMIT 1;',
                compact( "username", "password", "salt" )
            );
        }

        public function authenticateUser( $username, $password ) {
            $res = db(
                'SELECT
                    userid, password, salt
                FROM
                    users
{'fraction_non_alphanumeric': 0.10252532889762589, 'fraction_numerical': 0.002570694087403599, 'mean_word_length': 0.952760555063478, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6369573', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1517, 'n_words': 391}