Skip to content

Commit b55a6c6

Browse files
authored
Merge pull request #8 from Zanark/php_forum
Added Password encryption to prevent SQL Injection
2 parents fc3c9d8 + 574d353 commit b55a6c6

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

forum/connect.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
$database['username'] = "root";
88
$database['password'] = "";
99

10-
$link = mysqli_connect($database['host'] , $database['username'] , $database['password']);
10+
$link = mysqli_connect($database['host'] , $database['username'] , $database['password'] , $database['name'] );
1111

1212
if($link){
1313
echo "<b>Successfully</b> connected to database : " . $database['name'] . "<br/><br/>";

forum/forum_functions.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,18 @@ function checkInvalidCharacters($text) {
55
return(bool) preg_match("/[^\w-.]/" , $text );
66
}
77

8+
function encrypt_pswd($input , $rounds = 9 ){
9+
10+
$salt = "";
11+
12+
$saltChars = array_merge(range('A' , 'Z') , range('a' , 'z') , range('0' , '9') );
13+
14+
for($i = 0 ; $i < 22 ; $i++)
15+
{
16+
$salt .= $saltChars[array_rand($saltChars)];
17+
}
18+
19+
return crypt($input , sprintf('$2a$%02d$' , $rounds) . $salt);
20+
}
21+
822
?>

forum/register_parse.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,24 @@
2222
else {
2323
if (strlen($password) >= $minpl) {
2424

25+
$password = encrypt_pswd($password);
26+
2527
$sql = "INSERT INTO forum.users(username , password)
26-
VALUES ('$username' , '$password');
28+
VALUES ( ? , ? );
2729
";
2830

29-
$res = mysqli_query($link , $sql);
31+
$stmt = $link->prepare($sql);
32+
$stmt->bind_param('ss' , $username , $password);
3033

31-
if($res){
34+
//$res = mysqli_query($link , $sql);
35+
36+
if($stmt->execute()){
3237
echo "<b>Successfully Registered</b> as : " . $username . "<br/><br/>";
3338
}
3439

3540
else {
3641
echo "<b>Registration Failed</b><br/><br/>";
37-
echo "Error is => " . mysql_error();
42+
echo "Error is => " . mysqli_error($link);
3843
}
3944

4045

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