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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T01:41:58+00:00 2026-05-30T01:41:58+00:00

Notes: I’m still fairly new to php This login form seems to work perfectly

  • 0

Notes:

  • I’m still fairly new to php
  • This login form seems to work perfectly fine if I don’t hash the password.
  • I’ve tried md5, sha256 and now I’ve left it at sha1. None of these work.
  • I first used echo sha1("password"); to find out what the hash for my password would be, I then copied that hash and pasted it manually with phpMyAdmin. I’m not sure if this is what the issue is or not.

Anyways here is the code:

<?php
session_start();
require("config.php");

if(isset($_POST['submit'])) {

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

    $loginsql = "SELECT * FROM login WHERE username = '" . $username .
    "' AND password = '" . $password . "'";
    $loginresult = mysql_query($loginsql);
    $loginnumrows = mysql_num_rows($loginresult);

    if($loginnumrows == 1) {
        $loginrow = mysql_fetch_assoc($loginresult);
        session_register("USERNAME");
        session_register("USERID");

        $_SESSION['USERNAME'] = $loginrow['username'];
        $_SESSION['USERID'] = $loginrow['id'];

        header("Location: " . $config_basedir . "controlpanel.php");
    }
    else{
        echo "<p>Incorrect Login, please try again!</p>";
    }
}
else{

}
?>

I’m really not too sure where to go with this. I’m sure my code could be more efficient but as I mentioned in the notes, it does work when I don’t hash the password. Thank you for reading.

  • 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-30T01:42:01+00:00Added an answer on May 30, 2026 at 1:42 am

    If it works when you don’t hash the password, it sounds like your passwords are stored in the database as plaintext – that would be where I would check.

    The other thing that might be happening is mysql_real_escape string should be used on the other side of the sha1 so it doesn’t interfere with the exact input.

    So it should be: mysql_real_escape_string(sha1($_POST['password']));
    That might change things a bit.

    Note: Although sha1 doesn’t currently have any known security issues so it should be safe to put directly into the database without the mysql escape, somebody once told me to always make sure everything that goes into the database should be cast or escaped just in case a security vulnerability is found in something like sha1 or md5.

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

Sidebar

Related Questions

I am new to xpages in Lotus Notes and need to work with the
Coles Notes version: index.php?map_id=foo is loaded into iframe on www.not-my-domain.com. index sets SESSION['map_id'] =
I wish to play MIDI like notes from the C# XNA program. I don't
UPDATE As Mathias notes below, this exact problem has been reported and resolved here:
I have notes document with rich text field. In this RTF there is attachment
The Notes section in the function documentation of ignore_user_abort() suggest that PHP cannot detect
The Freemarker documentation notes: ...some Web Application Frameworks don't use FreemarkerServlet, so include_page is
This NHibernate blog entry notes how detached QueryOver queries (analogous to DetachedCriteria ) can
How to interpret the statements below: Notes bean = null; bean = new Notes();
C++ Notes: Array Initialization has a nice list over initialization of arrays. I have

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.