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 6706387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:30:53+00:00 2026-05-26T07:30:53+00:00

Before inserting data to the database, I encrypted the user name and password like

  • 0

Before inserting data to the database, I encrypted the user name and password like this:

 $userName=strip_tags($userName);
  $pass=strip_tags($pass);

  $userName= htmlentities($userName, ENT_QUOTES, 'UTF-8');
  $pass= htmlentities($pass, ENT_QUOTES, 'UTF-8');


  $userName=mysql_real_escape_string($userName);
  $pass=mysql_real_escape_string($pass);


   $salt = 'SHIFLETT';
   $password_hash = md5($salt . md5($pass.$salt));

This was done to prevent SQL attacks and general SQL injections.

Now I want to check the pass and name the user gives me when logging in. I repeated the same process of escaping character stripping, and escaping special characters.
So here is my function to check the pass:

   function validateLogin($user_name, $pass)
   {
  $userName=strip_tags($userName);
  $pass=strip_tags($pass);

  $userName= htmlentities($userName, ENT_QUOTES, 'UTF-8');
  $pass= htmlentities($pass, ENT_QUOTES, 'UTF-8');


  $userName=mysql_real_escape_string($userName);
  $pass=mysql_real_escape_string($pass);


   $salt = 'SHIFLETT';
   $password_hash = md5($salt . md5($pass.$salt));

   $result=mysql_query("SELECT COUNT(*) AS Result FROM users WHERE user_name='$user_name' AND pass='$password_hash'");

   mysql_close();

   if($row=mysql_fetch_array($result))
   {
       if($row['Result']>0)
       {
           echo "Login successful";
       }
       else
       {
           echo "Login unsuccessful";
       }
   }
   }

My question is with all those security precautions, will validation work? will MD5 return the same pass if I used the same MD5 encoding on the insert and then on the select statement?

  • 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-05-26T07:30:53+00:00Added an answer on May 26, 2026 at 7:30 am

    For flexibility, you should make a function to hash (not encrypt) your password. Also, use a stronger algorithm than md5 (like sha512 used in my example).

    function hashPassword($str)
    {
            return hash("sha512", $str . "salt");
    }
    

    I also recommend using mysql_real_escape_string.

    $password_hash = hashPassword($_POST['password']);
    $username = mysql_real_escape_string($_POST['username']);
    

    And use an auto_incremented int instead and select it.

    mysql> create table users (
    -> id int primary key auto_increment,
    -> username varchar(20),
    -> password char(128)); 
    

    Then simply compare the returned row with the username and password.

    $check = "select id from users where username = '$username' and password = '$password_hash'";
    $result = mysql_query($check);
    
    if(mysql_num_rows($result))
    {
        echo "<p>Login was successful!</p>\n";
    }
    

    To answer your question: yes, comparing a hashed password with a hashed string in the database will work.

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

Sidebar

Related Questions

I'm writing a routine that validates data before inserting it into a database, and
When inserting data in my database with linq to sql i get this exception
DetailsView1.DefaultMode = DetailsViewMode.Insert; After inserting how can i Preview Data before Submitting/Inserting data in
What is the recommended method for escaping variables before inserting them into the database
i have table in my database that have senestive data such as password field
Is pg_escape_string or mysql_escape_string enough to sanitize a string before inserting data into a
i have a data validation class method where i check the user input before
In my android application I am inserting and displaying data from a SQLite database.
Being a self-taught newbie, I created a large problem for myself. Before inserting data
I want to validate the data contained by Value Objects before inserting into the

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.