Login module prevents malicious user client attacks

Source: Internet
Author: User
Method: remove dangerous characters using functions:
1. Create a temporary String Array for saving strings
2. Get the length of the string
3. replace dangerous characters one by one
4. Return the processed string

Eg.
Public static string clearstringinput (string sinputstring, int imaxlength)
{
// Construct a temporary String Array
Stringbuilder retval = new stringbuilder ();
If (sinputstring! = NULL) & sinputstring! = String. Empty)
{
// Clear the white space at both ends of the string
Sinputstring = sinputstring. Trim ();
// Set the length of the string
If (sinputstring. length> imaxlength)
{
Sinputstring = sinputstring. substring (0, imaxlength );
}
For (INT I = 0; I <imaxlength; I ++)
{
Switch (sinputstring [I])
{
// Replace dangerous characters
Case '"': retval. append (" & quot; "); break;
Case '<': retval. append ("& lt;"); break;
Case '>': retval. append ("& gt"); break;
Default: retval. append (sinputstring [I]); break;
}
}

// Replace the character "'"
Retval. Replace ("'","");
}
// Return the processed string
Return retval. tostring ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.