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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:15:57+00:00 2026-06-16T00:15:57+00:00

I am using a database someone else produced (and I am not really authorised

  • 0

I am using a database someone else produced (and I am not really authorised to change it). However, as I was looking into the stored procedures within the database I noticed the following procedure:

DELIMITER $$

CREATE PROCEDURE `logIn`(userName varChar(50), userPass varChar(50))
BEGIN
  declare userID int;

  SELECT 
    u.userID INTO userID 
  FROM
    users u
  WHERE
    u.userName=userName 
    AND u.userPassword=MD5(userPass);

  IF (IFNULL(uID,-1) > 0) THEN
    select 1 as outMsg;
  ELSE
    select 0 as outMsg;
  END IF;
END$$

with the corresponding table users having three columns: userID INT, userName VARCHAR(50) and userPassword VARCHAR(50).

As I am not very good at this, could someone let me know whether the input for such a function needs to be sanitised as to not allow any SQL injections and if not – why? A general rule of thumb would be very much appreciated.

P.S. This function will be called from a JS script on a form submit.

  • 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-16T00:15:58+00:00Added an answer on June 16, 2026 at 12:15 am

    There are a few rules of thumb here that depend on the underlying datatype and how it’s inserted into the database.

    First, Parameterized queries are always best for SQL Injection protection.. but.. if you can’t change that..

    String type:

    1. Remove any single quotes
      OR
      Replace any single quotes with the single quote twice.

    2. Replace any of the following characters with their encoded alternative;

      • >
      • <
      • “
      • ;
      • (chr 34)
      • )
      • (
      • For example.. ) is replaced with & #x29;

        -(the space in the above example is so you’ll see the code, remove it to get “)”)

    For a datatype other then string, check that the datatype is sane and remove any character that shouldn’t be in the datatype. If it’s an integer, make sure the string that you’re passing in is an integer. This can commonly be done by casting to the type in code. The cast will either work.. or cause an error. It’s also good to check that the datatype min and maxes have not been exceeded. For example.. If I was checking for an integer, I might use code similar to this:

    var myInt = parseInt(param);

    Then I might check it’s bounds to be sure it’s less then the maximum integer value and greater then the minimum integer value.

    That should be good enough to prevent a SQL Injection attack…

    And.. since you have not posted the code that actually interfaces with the database… As an added precaution.. you may also want to remove –,`,%,”,”, “”.

    You only want ‘sane’ values getting to the database call.. so an integer like, $309 wouldn’t make sense, you’d want to remove the $.. . probably by using a regex replace for any non numeric characters a comma and a period.
    [^[0-9,.]]

    Be extra cautious.

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

Sidebar

Related Questions

I use database that has been created by someone else and I can't change
I would like to access a MySQL database using PHP. Can someone please explain
I am working on maintaining someone else's code that is using multithreading, via two
Instead of using a table plugin by someone else, I choose to do it
Below is part of a PHP database class someone else wrote, I have removed
I'm reading someone else's Django code, using PostgreSQL, and this is something I don't
I'm importing a flat file into a database using a Data Flow Task in
I'm currently working on someone else's database where the primary keys are generated via
I'm using Database Helper and I got an error saying SQLiteException near / syntax
I've been using Database First, EF 4.1 I am getting The entity type List`1

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.