Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8314205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:44:28+00:00 2026-06-08T20:44:28+00:00

I’ve recently set up my own dedicated server and installed everything that is necessary

  • 0

I’ve recently set up my own dedicated server and installed everything that is necessary to write PHP scripts etc. But I seem to have an issue when I’m returning an encrypted password from my MySQL databases, and I can’t tell if it’s something to do with my PHP configuration or whether it’s something to do with my MySQL configuration. Basically what is happening is when I use PDO to return the encrypted password from the database it looses certain characters, so when PHP goes to compare the encrypted password the user entered on the login with the password held in the database it throws an error.

Here’s an example:

The password entered by the user after encryption:
�#7��”�����8wŖQE��4YW�6�’��u�

The password returned from the database: ?#7??”?????8w?QE??4YW?6?’??u?

The ‘�’ characters seem to be getting changed to ‘?’ characters :S

I’ve checked the passwords in PHPMyAdmin to see if it was missing any characters, but the passwords match, so something is going a rye somewhere in between, and I am unsure whether it’s to do with PHP settings or MySQL.

Here’s my scripts:

Hash and Salt Script (modules.php):

<?php


        /* Initialises the username variable. */
        $username = $_SESSION['username'];

        /* If the user has changed their details then this block of code will make the changes to the database. 
        if(isset($_POST['detailsChanged']) == 1)
        {

            $statement = $conn -> prepare("UPDATE people SET Firstname = :firstname, Surname = :surname, Email = :email WHERE Username = :username ");

            $statement->bindParam(':firstname', $_POST['Firstname'], PDO::PARAM_INT);
            $statement->bindParam(':surname', $_POST['Surname'], PDO::PARAM_INT);
            $statement->bindParam(':email', $_POST['Email'], PDO::PARAM_INT);
            $statement->bindParam(':username', $username, PDO::PARAM_INT);
            $statement->execute();

        }*/

        if(isset($_SESSION["passed"]) == 1)
        {

            $statement = $conn->prepare("SELECT * FROM people WHERE username = '".$username."'");

            $statement->execute();  

            $result = $statement->fetch();

            $firstname = $result['Firstname'];
            $surname = $result['Surname'];
            $username2 = $result['Username'];

        }
        function pbkdf2( $p, $s, $c, $kl, $a = 'sha256' ) {

            $hl = strlen(hash($a, null, true)); # Hash length
            $kb = ceil($kl / $hl);              # Key blocks to compute
            $dk = '';                           # Derived key

            # Create key
            for ( $block = 1; $block <= $kb; $block ++ ) {

                # Initial hash for this block
                $ib = $b = hash_hmac($a, $s . pack('N', $block), $p, true);

                # Perform block iterations
                for ( $i = 1; $i < $c; $i ++ )

                    # XOR each iterate
                    $ib ^= ($b = hash_hmac($a, $b, $p, true));

                $dk .= $ib; # Append iterated block
            }

            # Return derived key of correct length
            return substr($dk, 0, $kl);
        }
?>

PDO initialisation (Login and Password removed for security reasons)(connection.php):

<?php 

$login = "*******";
    $password = "********";

    $dsn = "mysql:host=localhost;dbname=wishpiggy";
$opt = array(
    // any occurring errors wil be thrown as PDOException
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    // an SQL command to execute when connecting
    PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'UTF8'"
);

    $conn = new PDO($dsn, $login, $password);
    $conn->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES 'utf8'");
?>

Login Page:

<?php ob_start(); session_start(); include ('sql_connect/connection.php'); include('sql_connect/modules.php');

    //This section of code checks to see if the client is using SSL, if not 
    // if($_SERVER["HTTPS"] != "on")
    // {
    //        header("HTTP/1.1 301 Moved Permanently");   
    //        header("Location: https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]);
    //        exit();
    // }

    //This if statement checks to see if the session variable 'username' is set, and if so it will redirect the user to their profile page.

    if(isset($_SESSION["username"]))
    {
        header("Location: /home/");
    }

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Wish Piggy</title>
    <link href="css/styles.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    <script type="text/javascript" src="js/loginjs.js"></script>
</head>

<body>

    <div class="index_div">
        <div class="logo"><img src="img/wish_piggy.jpg" alt="" />
        </div>
        <div class="text"><span>89% Fulfilled</span>
        </div>
        <div class="bar"><img src="img/wish_piggy_bar.jpg" alt="" />
        </div>
        <div class="text">
            <div class="text_l"><p>1,000,000 People</p>
            </div>
            <div class="text_r"><p>9,000,838 Wishes</p>
            </div>
        </div>
        <div class="sign_in"><a id="show-panel" href="#"></a>
        </div>
    </div>

    <div id="lightbox-panel">
        <form id="loginForm" name="form" action="index.php" method="post" >
            <input name="submitted" type="hidden" value="1" /> 
            <div class="login_label"><img src="img/wish_piggy_login.jpg" alt="" /><a id="open_signin" href="#">SIGN UP HERE</a><p>Login</p><a id="close-panel" href="#"></a>
            </div>
            <div class="login_input"><input name="email" type="text" value="<?php if(isset($_COOKIE['username']) && $_COOKIE['username'] != ""){echo $_COOKIE['username']; $_SESSION["username"] = $_COOKIE['username']; $_SESSION["passed"] = 1; header("Location: /home/");}else{echo "Email";} ?>" onclick="this.value=''" />
            </div>
            <div class="input_label"><span>(e.g. johndoe@email.com)</span>
            </div>
            <div class="login_input"><input name="password" type="password" value="Password" onclick="this.value=''" />
            </div>
            <div class="input_label"><a href="#">Forgot Password</a>
            </div>
            <div class="login_submit">
                <div class="login_checkbox"><input name="remember" type="checkbox" value="" /> <span>Remember me</span>
                </div>
                <div class="login_submit_input"><input name="submit" type="submit" value=""/>
                </div>
            </div>
        </form>
    </div>
    <div id="lightbox"></div>

    <div id="lightbox-panel2">
        <div class="inner_lightbox2"><img src="img/wish_piggy_login.jpg" alt="" /><a id="close-panel2" href="#"></a>
        </div>
        <div class="signup_form">
            <form action="index.php" method="post">   
                <input name="submitted" type="hidden" value="1" /> 
                <div class="signup_form_label"><span>Firstname:</span>
                </div>
                <div class="signup_form_input"><input name="firstname" type="text" />
                </div>
                <div class="signup_form_label"><span>Surname:</span>
                </div>
                <div class="signup_form_input"><input name="surname" type="text" />
                </div>
                <div class="signup_form_label"><span>Email:</span>
                </div>
                <div class="signup_form_input"><input name="email" type="text" />
                </div>
                <div class="signup_form_label"><span>Confirm Email:</span>
                </div>
                <div class="signup_form_input"><input name="emailConfirm" type="text" />
                </div>
                <div class="signup_form_label"><span>Password:</span>
                </div>
                <div class="signup_form_input"><input name="password" type="text" />
                </div>
                <div class="signup_form_label"><span>Confirm Password:</span>
                </div>
                <div class="signup_form_input"><input name="passwordConfirm" type="text" />
                </div>
                <div class="signup_form_label2"><img src="img/wish_piggy_captcha.jpg" alt="" />
                </div>
                <div class="signup_form_input2"><input name="" type="text" />
                </div>
                <div class="signup_form_submit"><input name="" type="button" value="register" />
                </div>
            </form>
        </div>
    </div>
    <?php
        if(isset($_POST["submitted"]) == 1)
        {
            echo "caught data!";
            $email = $_POST["email"];
            $password = $_POST["password"];
            if($password == "")
            {
                die ("Your username or password is incorrect.");
            }

            $usernameValidated = 0;

            $statement = $conn->prepare("SELECT password FROM users WHERE email = :name");
            $statement->bindParam(":name", $email);
            $statement->execute();

            $passCompare = $statement->fetch();
            $passSubmitHashed = pbkdf2($password, "butterScotch", 1000, 32);
            echo $passSubmitHashed;
            echo " || ";
            echo $password;
            if($passSubmitHashed == $passCompare['password'])
            {
                $usernameValidated++;
            }
            echo "hurrdurr || " . $passCompare['password'];
            if($usernameValidated == 0)
            {

                die("Your username or password is incorrect..");

            }

        }
        if(isset($_POST["submitted"]) == NULL || isset($usernameValidated) > 0)
        {
            echo "<style> #text_contents{display: none;}</style>";
        }   

        if(isset($usernameValidated) >= 1)
        {
            $_SESSION["username"] = $username;
            $expiry = 60 * 60 * 6 + time();
            setcookie('username', $username, $expiry);
            $_SESSION["passed"] = $_POST["submitted"];

            header("Location: /profile/");
        }
        ob_end_flush();
    ?>
    <div id="lightbox2"></div>
    <?php ob_end_flush(); ?>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:44:32+00:00Added an answer on June 8, 2026 at 8:44 pm

    Encode the password simply using base64_encode (before saving it, and when comparing it) 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.