What's new

Closed Md5 registration in php

Status
Not open for further replies.

syml1nk

Addict
Joined
Nov 25, 2016
Posts
116
Reaction
59
Points
96
Creating Database Connection
save this as config.php

PHP:
 $database = new PDO ("mysql:host=localhost;dbname=db_name", 'root', 'user_pw');

Creating Registration Form
save this as index.php

PHP:
<div>
<form method="POST" action="register.php">
  <div class="form-group">
    <label>Email Address</label>
    <input type="email" name="email" class="form-control" placeholder="Email Address" required>
  </div>
  <div class="form-group">
    <label>Password</label>
    <input type="password" name="password" class="form-control" placeholder="Password" required>
  </div>
  <div class="form-group">
    <label>Re-type Password</label>
    <input type="password" name="re_password" class="form-control" placeholder="Re-type Password" required>
  </div>
  <button type="submit" name="btn_submit" class="btn btn-primary">Submit</button>
</form>
</div>

Inserting Data to Database
save this as register.php
PHP:
require_once ('config.php');

if (isset($_POST['btn_submit'])) {

$email = $_POST['email'];
$password = md5($_POST['password']);
$re_password = md5($_POST['re_password']);

if ($password != $re_password) {
    echo "<script>alert('Your Password does not match . . .'); window.location = 'index.php' </script>";
}    else

{
$database->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$insert_query = "INSERT INTO tbl_user (email, password, re_password)
VALUES (?, ?, ?)";

$insert = $database->prepare($insert_query);
$insert->execute(array($email, $password, $re_password));

echo "<script>alert('Account successfully added!'); window.location='index.php'</script>";
}
}

Output
upload_2018-8-14_20-21-15.png
 

Attachments

Di na po secure yung md5, di na safe gamitin yung mysql, gamit na po tayo ng latest na mysqli. si na po safe yan.
yung bagong php meron na sila built-in na pang encrypt ng password.
 
why still use md5 instead of AES? If push na push kaparin sa md5 lagyan mo lang ng salt or added patterns sa password.
 
Status
Not open for further replies.

Similar threads

Back
Top