src/Password/DjangoPassword.php
public function hash($password) {
        if ($this->hashMethod === 'crypt') {
            $salt = $this->generateCryptSalt();
            try {
                $hash = crypt($password, $salt);
            } catch (\Exception $ex) {
                throw new \Exception("$salt is an invalid salt.", $ex);
            }
        } elseif (in_array($this->hashMethod, hash_algos())) {
            $salt = base64_encode(openssl_random_pseudo_bytes(12));
            $hash = hash($this->hashMethod, $salt.$password);
        } else {
            throw new \Exception("The {$this->hashMethod} hash method is invalid.", 500);
        }

        $result = $this->hashMethod.'$'.$salt.'$'.$hash;
        return $result;
    }
public function hash($password) {
        if ($this->hashMethod === 'crypt') {
            $salt = $this->generateCryptSalt();
            try {
                $hash = crypt($password, $salt);
            } catch (\Exception $ex) {
                throw new \Exception("$salt is an invalid salt.", $ex);
            }
        } elseif (in_array($this->hashMethod, hash_algos())) {
            $salt = base64_encode(openssl_random_pseudo_bytes(12));
            $hash = hash($this->hashMethod, $salt.$password);
        } else {
            throw new \Exception("The {$this->hashMethod} hash method is invalid.", 500);
        }

        $result = $this->hashMethod.'$'.$salt.'$'.$hash;
        return $result;
    }
Hashes a plaintext password.

@param string $password The password to hash.
@return string Returns the hashed password.
@throws \Exception Throws an exception when the hash method is invalid.