|
5 | 5 |
|
6 | 6 |
|
7 | 7 | require_once "config.php"; |
8 | | - //data to enter |
9 | 8 |
|
| 9 | + //SQL Statement |
10 | 10 | $sql = "INSERT INTO passwordentrys (name, password, url, userid, username,keyy) VALUES (?, ?, ?, ? ,?,?)"; |
11 | 11 |
|
| 12 | + //Initialiaze validation variables |
12 | 13 | $validation = true; |
13 | 14 | $validationErrorText = ""; |
14 | 15 |
|
| 16 | + //Prepare statement |
15 | 17 | if ($stmt = $mysqli->prepare($sql)) { |
16 | 18 | // Bind variables to the prepared statement as parameters |
17 | 19 | $stmt->bind_param("ssssss", $param_name, $param_password, $param_url, $param_userid, $param_username, $param_keyy); |
18 | 20 |
|
| 21 | + |
| 22 | + //Validate Data for length |
19 | 23 | if (strlen($_POST["name"]) >= 45) { |
20 | 24 | $validation = false; |
21 | 25 | $validationErrorText .= "The name cannot be longer than 45 characters <br>"; |
|
33 | 37 | $validationErrorText .= "The username cannot be longer than 45 characters <br>"; |
34 | 38 | } |
35 | 39 |
|
| 40 | + //Validate data for isset |
36 | 41 | if (!(isset($_POST["name"]) && isset($_POST["password"]) && isset($_POST["url"]) && isset($_POST["username"]))) { |
37 | 42 | $validation = false; |
38 | 43 | $validationErrorText .= "Please make sure all fields are filled out! <br>"; |
|
44 | 49 | $ciphertext = sodium_crypto_secretbox($_POST["password"], $nonce, $key); |
45 | 50 | $encoded = base64_encode($nonce . $ciphertext); |
46 | 51 |
|
47 | | - |
| 52 | + //If validation passed then set parameters and execute |
48 | 53 | if ($validation) { |
49 | 54 | // Set parameters |
50 | 55 | $param_name = htmlentities($_POST["name"]); |
|
55 | 60 | $param_username = htmlentities($_POST["username"]); |
56 | 61 |
|
57 | 62 |
|
58 | | - // Attempt to execute the prepared statement |
| 63 | + // Attempt to execute the prepared statement and redirect if successful |
59 | 64 | if ($stmt->execute()) { |
60 | 65 | header("location: passwordmanager.php"); |
61 | 66 | } else { |
|
99 | 104 | <br> |
100 | 105 | <br> |
101 | 106 |
|
| 107 | + <!-- |
| 108 | + Form to upload password |
| 109 | + includes client-side validation |
| 110 | + --> |
102 | 111 | <form action="uploadPassword.php" method="post" enctype="multipart/form-data"> |
103 | 112 | <div class="container"> |
104 | 113 | <div class="row"> |
|
0 commit comments