Skip to content

Commit f33bdf8

Browse files
committed
Added check for special characters in username & set min password length = 8
1 parent 5ac194c commit f33bdf8

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

forum/forum_functions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
function checkInvalidCharacters($text) {
4+
5+
return(bool) preg_match("/[^\w-.]/" , $text );
6+
}
7+
8+
?>

forum/register_parse.php

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,50 @@
11
<?php
22

33
include("connect.php");
4+
include("forum_functions.php");
45

56
$username = $_POST['username'];
67
$password = $_POST['password'];
78

9+
$minpl = 8;
10+
811
/* echo "Registeration Details : ";
912
echo "Username : " . $username . "<br/><br/> Password : " . $password; */
10-
11-
$sql = "INSERT INTO forum.users(username , password)
12-
VALUES ('$username' , '$password');
13-
";
14-
15-
$res = mysqli_query($link , $sql);
1613

17-
if($res){
18-
echo "<b>Successfully Registered</b> as : " . $username . "<br/><br/>";
14+
if ( $username == "" || $password == ""){
15+
echo "Please fill in all the details <br/> Please check if you forgot to enter data in any of the fields <br/>";
1916
}
17+
2018
else {
21-
echo "<b>Registration Failed</b><br/><br/>";
22-
echo "Error is => " . mysql_error();
19+
if( checkInvalidCharacters($username) )
20+
echo "Username can only contain <br/><br/><ul><li> A to Z </li><li> a to z </li><li> 0 to 9 </li><li> . and _ </li></ul>";
21+
22+
else {
23+
if (strlen($password) >= $minpl) {
24+
25+
$sql = "INSERT INTO forum.users(username , password)
26+
VALUES ('$username' , '$password');
27+
";
28+
29+
$res = mysqli_query($link , $sql);
30+
31+
if($res){
32+
echo "<b>Successfully Registered</b> as : " . $username . "<br/><br/>";
33+
}
34+
35+
else {
36+
echo "<b>Registration Failed</b><br/><br/>";
37+
echo "Error is => " . mysql_error();
38+
}
39+
40+
41+
}
42+
43+
else {
44+
echo "Password is too short. <br/> <b>Minimum length is 8 characters</b>";
45+
}
46+
}
2347
}
48+
2449

2550
?>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy