Cara Membuat API Login dan Regitrasi Menggunakan PHP

farizdotid

Seorang manusia biasa yang mempunyai fokus ke bidang pemrograman android dan ngeblog mengenai teknologi.

You may also like...

12 Responses

  1. Krismawan says:

    file downloadnya nggak bisa gan

  2. oktayossy says:

    gan itu buat dipostmannya gmna ya, kurang paham di masukin responnya

  3. ricco says:

    gan saya sudah ikuti sampai tahap ke sebelas.. namun saat di coba
    http://localhost/mahasiswa/login.php
    http://localhost/mahasiswa/register.php

    respon nya error seperti ini:
    untuk yang login.php

    Warning: require_once(include/DB_Functions.php): failed to open stream: No such file or directory in D:\xampp\htdocs\bantosan\login.php on line 2

    Fatal error: require_once(): Failed opening required ‘include/DB_Functions.php’ (include_path=’.;D:\xampp\php\PEAR’) in D:\xampp\htdocs\bantosan\login.php on line 2

    untuk yang register.php

    Warning: require_once(include/DB_Functions.php): failed to open stream: No such file or directory in D:\xampp\htdocs\bantosan\register.php on line 3

    Fatal error: require_once(): Failed opening required ‘include/DB_Functions.php’ (include_path=’.;D:\xampp\php\PEAR’) in D:\xampp\htdocs\bantosan\register.php on line 3

  4. dwi says:

    GAn.. saya nyoba kok error nya gini ya..

    Warning: require_once(mobile/DB_Connect.php): failed to open stream: No such file or directory in
    C:\xampp\htdocs\aplikasipmbuin\mobile\DB_Functions.php on line
    9

    Fatal error: require_once(): Failed opening required ‘mobile/DB_Connect.php’ (include_path=’C:\xampp\php\PEAR’) in
    C:\xampp\htdocs\aplikasipmbuin\mobile\DB_Functions.php on line
    9

  5. tamvann says:

    Gan saya kok error yaa, errornya gini

    Warning: require_once(include/DB_Functions.php): failed to open stream: No such file or directory in C:\xampp\htdocs\PKost\login.php on line 2

    Fatal error: require_once(): Failed opening required ‘include/DB_Functions.php’ (include_path=’C:\xampp\php\PEAR’) in C:\xampp\htdocs\PKost\login.php on line 2

    dan DB_Function.php nya gini gan

    conn = $db->connect();
    }

    // destructor
    function __destruct() {

    }

    public function simpanUser($nama, $email, $password) {
    $uuid = uniqid(”, true);
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash[“encrypted”]; // encrypted password
    $salt = $hash[“salt”]; // salt

    $stmt = $this->conn->prepare(“INSERT INTO tbl_user(unique_id, nama, email, encrypted_password, salt) VALUES(?, ?, ?, ?, ?)”);
    $stmt->bind_param(“sssss”, $uuid, $nama, $email, $encrypted_password, $salt);
    $result = $stmt->execute();
    $stmt->close();

    // cek jika sudah sukses
    if ($result) {
    $stmt = $this->conn->prepare(“SELECT * FROM tbl_user WHERE email = ?”);
    $stmt->bind_param(“s”, $email);
    $stmt->execute();
    $user = $stmt->get_result()->fetch_assoc();
    $stmt->close();

    return $user;
    } else {
    return false;
    }
    }

    /**
    * Get user berdasarkan email dan password
    */
    public function getUserByEmailAndPassword($email, $password) {

    $stmt = $this->conn->prepare(“SELECT * FROM tbl_user WHERE email = ?”);

    $stmt->bind_param(“s”, $email);

    if ($stmt->execute()) {
    $user = $stmt->get_result()->fetch_assoc();
    $stmt->close();

    // verifikasi password user
    $salt = $user[‘salt’];
    $encrypted_password = $user[‘encrypted_password’];
    $hash = $this->checkhashSSHA($salt, $password);
    // cek password jika sesuai
    if ($encrypted_password == $hash) {
    // autentikasi user berhasil
    return $user;
    }
    } else {
    return NULL;
    }
    }

    /**
    * Cek User ada atau tidak
    */
    public function isUserExisted($email) {
    $stmt = $this->conn->prepare(“SELECT email from tbl_user WHERE email = ?”);

    $stmt->bind_param(“s”, $email);

    $stmt->execute();

    $stmt->store_result();

    if ($stmt->num_rows > 0) {
    // user telah ada
    $stmt->close();
    return true;
    } else {
    // user belum ada
    $stmt->close();
    return false;
    }
    }

    /**
    * Encrypting password
    * @param password
    * returns salt and encrypted password
    */
    public function hashSSHA($password) {

    $salt = sha1(rand());
    $salt = substr($salt, 0, 10);
    $encrypted = base64_encode(sha1($password . $salt, true) . $salt);
    $hash = array(“salt” => $salt, “encrypted” => $encrypted);
    return $hash;
    }

    /**
    * Decrypting password
    * @param salt, password
    * returns hash string
    */
    public function checkhashSSHA($salt, $password) {

    $hash = base64_encode(sha1($password . $salt, true) . $salt);

    return $hash;
    }

    }

    ?>

  1. May 14, 2017

    […] terlebih dahulu API Login dan Registernya. Agan bisa kesini ( Cara Membuat API Login dan Regitrasi Menggunakan PHP […]

  2. August 7, 2017

    […] folder htdocs agan lalu cari folder mahasiswa. Jika belum ada agan bisa ke artikel Cara Membuat API Login dan Regitrasi Menggunakan PHP terlebih […]

Leave a Reply

Your email address will not be published. Required fields are marked *