Modifying salt with android API for webservice development
I am using codes from a tutorial to create API for android login but the hashing on the system I really want to develop from is different, how can I change to fit my database?
<?php
class DB_Functions {
private $conn;
function __construct() {
require_once 'DB_Connect.php';
$db = new Db_Connect();
$this->conn = $db->connect();
}
function __destruct() {
}
public function storeUser($name, $email, $password) {
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"];
$salt = $hash["salt"];
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())");
$stmt->bind_param("sssss", $uuid, $name, $email, $encrypted_password, $salt);
$result = $stmt->execute();
$stmt->close();
if ($result) {
$stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
return $user;
} else {
return false;
}
}
public function getUserByEmailAndPassword($email, $password) {
$stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
if ($stmt->execute()) {
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
$salt = $user['salt'];
$encrypted_password = $user['encrypted_password'];
$hash = $this->checkhashSSHA($salt, $password);
if ($encrypted_password == $hash) {
return $user;
}
} else {
return NULL;
}
}
public function isUserExisted($email) {
$stmt = $this->conn->prepare("SELECT email from users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$stmt->close();
return true;
} else {
$stmt->close();
return false;
}
}
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;
}
public function checkhashSSHA($salt, $password) {
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
}
}
?>
Codes I want to modify to fit tutorials explanation:
<pre lang="PHP">else {
$passwordTest=false ;
$salt=$row["passwordStrongSalt"] ;
$passwordStrong=$row["passwordStrong"] ;
if ($passwordStrong!="" AND $salt!="") {
if (hash("sha256", $row["passwordStrongSalt"].$password)==$row["passwordStrong"]) {
$passwordTest=true ;
}
}
else if ($row["password"]!="") {
if ($row["password"]==md5($password)) {
$passwordTest=true ;
$salt=getSalt() ;
$passwordStrong=hash("sha256", $salt.$password) ;
try {
$dataSecure=array("passwordStrong"=> $passwordStrong, "passwordStrongSalt"=> $salt, "username"=> $username );
$sqlSecure="UPDATE gibbonPerson SET password='', passwordStrong=:passwordStrong, passwordStrongSalt=:passwordStrongSalt WHERE (username=:username)";
$resultSecure=$connection2->prepare($sqlSecure);
$resultSecure->execute($dataSecure);
}
catch(PDOException $e) {
$passwordTest=false ;
}
}
What I have tried:
To replace the hash statement but the api is not working. Is there a better way?