Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once "../config/config.php";
- class DevSystem
- {
- public static function addStudent($conn, $POST) {
- $stno = $POST["stno"];
- $status = $POST["status"];
- $sYear = $POST["sYear"];
- $session = $POST["session"];
- $lastname = $POST["lastname"];
- $firstname = $POST["firstname"];
- $middlename = $POST["middlename"];
- $birthdate = $POST["birthdate"];
- $sex = $POST["sex"];
- $username = $POST["username"];
- // Password generation
- $password_hash = password_hash($firstname, PASSWORD_BCRYPT);
- $gen_exp = explode("$",$password_hash);
- $gen_split = str_split($gen_exp[3], 6);
- // Replacement of non-alphanumeric characters
- $rand_int1 = rand(0, 9);
- $rep1 = str_replace(".", $rand_int1, $gen_split[3]);
- $rand_int2 = rand(0, 9);
- $rep2 = str_replace("/", $rand_int2, $rep1);
- // Hashing for DB
- $final_hash = password_hash($rep2, PASSWORD_BCRYPT);
- $stmt = $conn->db->prepare("INSERT INTO students (stno, status, sYear, session, lastname, firstname, middlename, birthdate, sex, username, password)
- VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- $stmt->bind_param(
- "sssssssssss",
- $stno,
- $status,
- $sYear,
- $session,
- $lastname,
- $firstname,
- $middlename,
- $birthdate,
- $sex,
- $username,
- $final_hash
- );
- $response = '';
- $response .= $stmt->execute() ? 'Student added. Password: ' . $rep2 : $stmt->error;
- if($stmt->error) {
- return $response;
- }
- $stmt->close();
- return $response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement