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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:41:42+00:00 2026-06-01T16:41:42+00:00

I have a a simple form to login using a username and password. I

  • 0

I have a a simple form to login using a username and password. I want to apply a whitelist to allow only certain characters. I dont know if anybody requires this but here is the code to retrieve the username and password:

$stmt = $conn2->prepare("SELECT username FROM users WHERE username = ? AND password = ?");

$stmt->bind_param("ss", $username, $password);      
$stmt->execute();
$stmt->store_result();

Do I incorporate something like this:

preg_replace( "/[^a-zA-Z0-9_]/", "", $stringToFilter );

If so, where do I include it within my code? And what happens if a user tries to input something other than what is in the whitelist?

ADDED: Ok well what about if it is during registration and it is using INSERT to store username and password?

//insert data
$stmt = $conn2->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");

//bind the parameters
$stmt->bind_param('sss', $username, $email, $password);
  • 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-01T16:41:44+00:00Added an answer on June 1, 2026 at 4:41 pm

    Add the filtering code before your INSERT during registration. Check that the string is not empty after filtering, so that a username of "!!*&%$#()*&#$" does not get inserted as a blank string.

    $username_clean = preg_replace( "/[^a-zA-Z0-9_]/", "", $_POST['username'] );
    
    if (!strlen($username_clean)){
    
        die("username is blank!");
    }
    
    $stmt = $conn2->prepare("INSERT INTO users (username, email, password) VALUES (?, ?, ?)");
    $stmt->bind_param('sss', $username_clean, $email_clean, $password_clean);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple login form that captures username/password with some simple Javascript (JQuery)
I have simple login form I am using SQLite database which has fields like
I have a simple html login form, deployed on Xcode using phonegap framework. When
There are some HTML based games (ie bootleggers.us) that have a simple login form
I have simple form like this which accepts only two values string action and
Have a simple form (only extract fields here) but for some reason the JQserilization
I have a simple form with some plain html input like bellow using ASP.NET
I have a simple form on a page and I want to auto submit
I would like to have a simple login form (or any form for that
i have a website that has a simple login form. the form posts to

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.