Login Script Help Needed

Started on the old forum in March 2016 · view the original in the archive · old links redirect here

4 replies · 148 views · started 10 years ago · 1 min read

2 participants
rajveer Developer · 104 posts #1

Hello Friends In Need Lil Login Validation Help Here is My Old Code

if ($_SERVER["REQUEST_METHOD"] == "POST")
{
    $nickname = isset($_POST['nick']) ? $_POST['nick'] : NULL ;
    $password = isset($_POST['pass']) ? $_POST['pass'] : NULL ;
    
    $clean_nick = preg_replace('/[^[:alnum:]]/', '', $nickname);
    $clean_pass = preg_replace('/[^[:alnum:]]/', '', $password);
    
    if (empty($nickname) or empty($password))
    {
        $error = '<div class="error">Wrong Nickname Or Password !</div>';
    }
    else if (strlen($nickname) < 3||strlen($password) < 3)
    {
        $error = '<div class="error">Username or Password is to short, it has to be longer than 3 chars</div>';
    }
    else if (strlen($clean_nick) < 3||strlen($clean_pass) < 3)
    {
        $error = '<div class="error">Username or Password Contains special chars. Allowed chars: A-Z, a-z, 0-9, - _ @</div>';
    }
    else
    {
        /// nothing here
    }
}

now i want to know is that is my clean_nick verify ok ??? i used this code from gumchat

 $clean_nick = preg_replace('/[^[:alnum:]]/', '', $nickname);
 $clean_pass = preg_replace('/[^[:alnum:]]/', '', $password

if (strlen($clean_nick) < 3||strlen($clean_pass) < 3)
    {
        $error = '<div class="error">Username or Password Contains special chars. Allowed chars: A-Z, a-z, 0-9, - _ @</div>';
    }

i want to do simply is make sure username and password are only A-Z 0-9 Or _- can anybody make change to my code it allows many chars now i want A-Z 0-9 Or _- Only

I Am Building Community Site

new.png

spiderwebs Developer · 193 posts #2

Rajveer

Use this

if(preg_match("/ [^-A-Za-z0-9._ ]/", $nickname)){ // invalid character }

E107 Security Team Leader Proudly Support AccountLab Plus Billing Software

Want your Apps to be Developed ??? mail us your requirement at info@csarlab.com

spiderwebs Developer · 193 posts #5

yes its good

E107 Security Team Leader Proudly Support AccountLab Plus Billing Software

Want your Apps to be Developed ??? mail us your requirement at info@csarlab.com

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close