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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:11:10+00:00 2026-05-27T19:11:10+00:00

I use the following code to store user password into a mysql table with

  • 0

I use the following code to store user password into a mysql table with the password column being a BINARY(20) type:

$salted_hash = sha1($salt . $password);
$sql = sprintf("INSERT INTO foo(user, password) VALUES ('guest', UNHEX('%s'))", $salted_hash);

The select query to match password looks like:

$salted_hash = sha1($salt . $password);
$sql = sprintf("SELECT `userID` FROM `foo` WHERE `user`='guest' AND `password`=UNHEX('%s')", $salted_hash);

The code works fine when I connect to a web server running on a windows or mac machine. However, my production web host is a linux machine, and the SELECT is failing there.

I can only phpMyAdmin to my web host (mhpMyAdmin version 3.4.7.1). Through phpMyAdmin I execute the following query:

SELECT UNHEX('3530280EDB5AA715929266D1D6F0423ABC27B104')

The result displayed is the same number hex number 3530280EDB5AA715929266D1D6F0423ABC27B104, which seems to indicate that the UNHEX function is not doing anything on linux.

If I execute the same query in Sequel Pro on Mac I get 50(ÛZ§fÑÖðB:¼'±.

I’m not sure what’s going on and where to look. I’m thinking either phpMyAdmin cannot display binary or there is indeed some problem with UNHEX(seems unlike) Any help is appreciated.

  • 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-27T19:11:10+00:00Added an answer on May 27, 2026 at 7:11 pm

    It seems it’s a configurable setting: “Show binary contents as HEX”. I’ve tried your query in the same server…

    SELECT UNHEX('3530280EDB5AA715929266D1D6F0423ABC27B104')
    

    … but using two different clients. I can confirm that phpMyAdmin escapes binary output the way you’ve found. You can double check that the output is correct with:

    SELECT HEX(UNHEX('3530280EDB5AA715929266D1D6F0423ABC27B104'))='3530280EDB5AA715929266D1D6F0423ABC27B104'
    

    …, which should return 1, or running the original query with simple PHP script. To sum up: there’s nothing wrong with UNHEX().

    Most hosting services I’ve used actually allow external MySQL clients, you just need to enable it in the control panel. Make sure it’s not the case. It’s silly to use a dumb web client if you can connect with Sequel Pro.

    I suggest you do further debugging with your PHP code. It’s not clear to me how you build the hash to match (do you retrieve the salt in some other query?).

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

Sidebar

Related Questions

When a user log into my asp.net site I use the following code: FormsAuthentication.RedirectFromLoginPage(userid,
I use the following code to load an image into an scroll view. The
I'm about to code a php/mysql platform that does the following: Admin panel User
I use the following code to create countdowns in Javascript. n is the number
I use the following code to compile a cpp file to object file. g++
I use the following code try to create an array of string vectors, I
I use the following code to layout network drives on a system. I want
I use the following code: Calendar calendar = new GregorianCalendar(0,0,0); calendar.set(Calendar.YEAR, 1942); calendar.set(Calendar.MONTH, 3);
I use the following code to allocate a Console for a WinForm application. The
I use the following code: - (NSURLRequest *)connection:(NSURLConnection *)connection willSendRequest:(NSURLRequest *)request redirectResponse:(NSHTTPURLResponse *)response {

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.