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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:24:28+00:00 2026-06-01T15:24:28+00:00

This is an authentication script for a website. Is this safe? Is it recent

  • 0

This is an authentication script for a website. Is this safe? Is it recent programming? Is it obsolete? Are there “better more secure ways” I am very new but I don’t see too many places using header authorization.

Any help would be appreciated! This is the first login script I’ve ever made and also registration.. However I’m not sure I like the header authorization.

<?php
require_once('connectvars.php');
IF (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW'])) {
header('HTTP/1.1 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Register"');
exit('<h3> You must enter your username & password to continue');
}
$Dbc  = mysqli_connect('localhost', 'root', '', 'learn');
$user_username = mysqli_real_escape_string($Dbc, trim($_SERVER['PHP_AUTH_USER']));
$user_password = mysqli_real_escape_string($Dbc, trim($_SERVER['PHP_AUTH_PW']));
$query = "SELECT ID, Username from members where Username = '$user_username' AND " .
"Password = SHA1('$user_password')";
$data = mysqli_query($Dbc, $query);
if (mysqli_num_rows($data) == 1) {
$row = mysqli_fetch_array($data);
$user_id = $row['ID'];
$username = $row['Username'];
}
else {
header('http/1.1 401 unauthorized');
header('www-authenticate: basic realm="Register"');
}
echo ('<p class="Login"> yo are logged in as ' . $user_username . '.</p>'); 

if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$email = $_POST['email'];

if (empty($username) ){ 
echo "you forgot to enter a username.</br>";
}
if (empty($password)) {
echo "you forgot to enter a password.</br>";
}   
if (empty($email)) {
echo "you forgot to enter an email.</br>";
}

if(!empty($username) && !empty($password) && !empty($email))  {
$dbc = mysqli_connect('localhost', 'root', '', 'learn');
$checkusername = 'SELECT username FROM members where username = "'.$username.'"';
if (mysqli_num_rows(mysqli_query($dbc, $checkusername)) != 0) 
{
    echo "<font color = red> Username <font color = black><u>           $username</u></font> already exists in the database.</font></br>";

$checkemail = 'Select email FROM members where email = "'.$email.'"';
if (mysqli_num_rows(mysqli_query($dbc, $checkemail)) != 0)
        echo "<font color = red> Email <font color = black><u>     $email</u></font> already exists in the database.</font>";
    mysqli_close($dbc);
}
else 
{
$query = "INSERT INTO members VALUES (0, '$username', SHA1('$password'), '$email')";
mysqli_query($dbc, $query);
echo " Username: <font color = green ><u> $username</u></font> & Password: <font color = green><u> $password</u></font> have been added to the database.";
mysqli_close($dbc);
}
}   
}

?>
  • 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-01T15:24:30+00:00Added an answer on June 1, 2026 at 3:24 pm

    It’s wrong. mysqli supports parametrized queries; use them.

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

Sidebar

Related Questions

I'm trying to build an authentication script and i'm trying to get this one
I'm creating a website and I'm using facebook as my authentication. I did this
Question: Is this API authentication technique easily hackable? apiKey = 123456789 apiCallId = 1256341451
I need to add authentication to this function: function multiRequest($data, $options = array()) {
hi I am trying to get user profile information like this once the authentication
This application is using windows integrated authentication in IIS. No anonymous login. It's also
I was looking at an authentication system which had this code: # prevents a
I managed to get authentication to work by following the tutorial from this page
I've been following this tutorial: http://emumair.wordpress.com/2011/03/17/social-network-authentication-with-omniauth-and-authlogic/ . I've walked through it all and I'm
I have this on my web.config file: <authentication mode=Forms> <forms loginUrl=login.aspx defaultUrl=Venues.aspx /> </authentication>

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.