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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T20:03:57+00:00 2026-06-11T20:03:57+00:00

I have a very simple login/user registration script that stores passwords using sha1 and

  • 0

I have a very simple login/user registration script that stores passwords using sha1 and salt. I have the passwords and user creation working fine and storing everything in the database just fine, but when I try to log in with the credentials, it doesn’t work. I can’t seem to find anything upon searching this topic.

Here is my add user form:

session_start();
include("includes/resume.config.php");

// make sure form fields have a value and strip them
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
    die($problem);
}
    return $data;
}

// get form values, escape them and apply the check_input function
$name = $link->real_escape_string(check_input($_POST['name'], "Please enter a name!"));
$email = $link->real_escape_string(check_input($_POST['email'], "Please enter an email!"));
$password = $link->real_escape_string(check_input($_POST['password'], "Please enter a password!"));

// generate a random salt for converting passwords into MD5
$salt = bin2hex(mcrypt_create_iv(32, MCRYPT_DEV_URANDOM));
$saltedPW =  $password . $salt;
$hashedPW = sha1($saltedPW);

mysqli_connect($db_host, $db_user, $db_pass) OR DIE (mysqli_error());
// select the db
mysqli_select_db ($link, $db_name) OR DIE ("Unable to select db".mysqli_error($db_name));

 // our sql query
$sql = "INSERT INTO admins (name, email, password, salt) VALUES ('$name', '$email', '$hashedPW', '$salt');";

//save the updated information to the database          
mysqli_query($link, $sql) or die("Error in Query: " . mysqli_error($link));

if (!mysqli_error($link)) 
{
    header("Location: file_insert.php");
}   

And here is my login script: This is what is not working

function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
    die($problem);
}
    return $data;
}

if(isset($_POST['submitLogin'])) { //form submitted?

// get form values, escape them and apply the check_input function
$name = $link->real_escape_string(check_input($_POST['name'], "Please enter a name!"));
$password = $link->real_escape_string(check_input($_POST['password'], "Please enter a password!"));

$saltQuery = $link->query('SELECT salt FROM admins WHERE name = "'.$name.'"');

$salt = mysqli_fetch_assoc($saltQuery);
$saltedPW =  $password . $salt;
$hashedPW = sha1($saltedPW);

mysqli_connect($db_host, $db_user, $db_pass) OR DIE (mysqli_error());
// select the db
mysqli_select_db ($link, $db_name) OR DIE ("Unable to select db".mysqli_error($db_name));

$validate_user = $link->query('SELECT id, name, password FROM admins WHERE name = "'.$name.'" AND password = "'.$hashedPW.'"');

if ($validate_user->num_rows == 1) {
    $row = $validate_user->fetch_assoc();
    $_SESSION['id'] = $row['id'];
    $_SESSION['loggedin'] = TRUE;
    Header('Location: file_insert.php');
} else {
    print "<center><p style='margin-top: 200px; font-weight: bold;'>Invalid Login Information</p>";
    print "<a href='admin-login.php'>Click here</a> to return to the login page.</center>";
}
}
  • 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-11T20:03:59+00:00Added an answer on June 11, 2026 at 8:03 pm

    There may be more going on, but certainly one reason it isn’t working is because mysqli_fetch_assoc returns an array, and you are using it like a string.

    PHP would complain about an array to string conversion when you call $password . $salt since at this point $salt is an array. The result is that you get the word Array appended to the password which results in an incorrect hash. If you have display_errors off and/or error_reporting set to hide notices in php.ini then you wont see this message.

    If you change:

    $saltedPW =  $password . $salt;
    

    to:

    $saltedPW =  $password . $salt['salt'];
    

    then it should work.

    In addition, you should escape $salt before you insert it into the database because its possible it could contain null, unprintable, or single/double quotes since its randomly generated.

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

Sidebar

Related Questions

I have a very simple script that creates a user: <?php include 'mysqlserver.php'; session_start();
In my web admin area I have using very simple logic: session_start(); ob_start(); if(!isset($_SESSION['user'])){
I have a very simple question....I have multiple jsp files like login.jsp , Registration.jsp
I have this very simple login form with user and pass and I need
I have a very simple RSpec Capybara have_selector() that doesn't seem to be working
I have a very simple question. In FB tutorial https://developers.facebook.com/docs/mobile/ios/build/ it starts to login
I have a simple mobile app in Titanium that I'm using to debug the
I have built a very simple CakePHP website using the Auth component and have
I have the following data flow for a simple login form. User access controller
I have a very simple jQuery/ajax script for a membership driven website. The script

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.