import subprocess


def get_php_db_password(password):
    """
    Generates a password to be used within the site for database authentication. The
    password_hash function (http://php.net/manual/en/function.password-hash.php)
    generates us a nice secure password and takes care of things like salting and
    hashing.

    :param password:
    :type: str
    :return: password hash to be inserted into the DB for a user
    :rtype: str
    """
    proc = subprocess.Popen(
        ["php", "-r", "print(password_hash('{}', PASSWORD_DEFAULT));".format(password)],
        stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    (out, err) = proc.communicate()
    return out.decode('utf-8')
