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

  • Home
  • SEARCH
  • 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 8372475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:26:29+00:00 2026-06-09T14:26:29+00:00

I have a small web app that uses a simple username/password login scheme. I’ve

  • 0

I have a small web app that uses a simple username/password login scheme. I’ve noticed several times it won’t allow a user to login when they correctly input the password.

The code originally was just encrypting the user’s typed in password on initial registration as:

function encode5t($str) {
  for($i=0; $i<5;$i++)   {
     $str=strrev(base64_encode($str)); //apply base64 first and then reverse the string
  }
  return $str;
 }

 $password=mysql_real_escape_string($_POST['password']);
 $pass=encode5t($password);

and then $pass is inserted into a MySQL database. Then the same function is used to
encrypt the password on login and is checked against the database like so:

$username = $_POST['username'];
$psw = $_POST['password'];
$npsw=encode5t($psw);

$query = sprintf("SELECT * FROM members WHERE username='%s' AND password='%s'",
    mysql_real_escape_string($username),
    mysql_real_escape_string($npsw));

The problem arises depending on how the password is input into the form. If it’s simply typed in, there is no problem, but if the password is copied/pasted into the form (as from an email containing a newly generated password), it fails. The encryption function creates and entirely different hash and doesn’t match, so the user isn’t logged in.

I’ve played with the encoding and changed it to a just use md5() but I get the same end
result – a cut/paste results in a different hash than what simply typing the password into the form results in.

Is there something in the page encoding that would make a copy/paste text different from a typed one?

  • 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-09T14:26:30+00:00Added an answer on June 9, 2026 at 2:26 pm

    The problem is that when users paste in a username/password, it often has spaces before or after it. Run those fields through trim() to fix this.

    On another note, what you have isn’t all that secure. Your base64 string won’t fool anybody for long, and md5 should not be used for password hashes, especially when not salted. Try something a bit more robust, such as whirlpool. Finally, I suggest using prepared queries with PDO to avoid injection issues. You are escaping your data currently… that’s great! But, it is best not to take a chance with missing an escape somewhere.

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

Sidebar

Related Questions

I have small web app that generate PDF files as a report. I'm trying
I have a small app that a client uses to manually update some data.
I am developing a small web app that uses jQuery quite a lot. In
I have a web app that uses a flash uploader (swfuploader) and recently a
We have an MVC web app that uses FormsAuthentication and also stores a couple
I have an asp .net webforms app that uses forms authentication. For a small
I have an Azure web app that uses a startup task batch file (addtask.cmd)
I have a web app that I provide to small to medium-sized businesses as
I have a small web app I wrote that has a Dijit.layout.BorderContainer nested within
I have a small command line app that uses the Oracle client (specifically, Oracle.DataAccess).

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.