How to Secure Login Form using sql server DB
  • Hello i created a login form using SQL SERVER Backend but my login form password textbox also accept this type of input

    1) 1′ OR ’1′=’1--
    2) abc' or 1=1-- 
    etc

    is this anyway to protect my login form avoiding this type of inputs?
    hussainroyal
  • 3 Comments sorted by
  • Write a custom function to validate password input before send data to sql server table.You can use String.IndexOfAny(char[] anyOf) method to accomplish this.For example

    public bool ValidatePassword(char[] mychars)
    {
      if(String.IndexOfAny(mychars)>0)
      {
       return true;
      }
      return false;
    }

  • Some examples:
            // A.
    // Input.
    const string value1 = "Darth is my enemy.";
    const string value2 = "Visual Basic is hard.";

    // B.
    // Find first location of 'e' or 'B'.
    int index1 = value1.IndexOfAny(new char[] { 'e', 'B' });
    Console.WriteLine(value1.Substring(index1));

    // C.
    // Find first location of 'e' or 'B'.
    int index2 = value2.IndexOfAny(new char[] { 'e', 'B' });
    Console.WriteLine(value2.Substring(index2));
  • Hi Hussain
    Jaguar777 example is best if want to accept some character you can also try keypress event and can restrict user there.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Top Posters Weekly

Optimum Creative