Skip to content

Instantly share code, notes, and snippets.

@femmerling
Created April 3, 2013 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save femmerling/5300312 to your computer and use it in GitHub Desktop.
Save femmerling/5300312 to your computer and use it in GitHub Desktop.
Put this file in your OwnCloud root folder to have a create new user API. All you need to do is have a POST request to <host>/owncloud/owncloudUserCreateHack.php with username and password parameters and your user is created. Remember that this works under SQLite3. Adjust to MySQL or PostgreSQL or whatever engine query you're using.
<?php
require_once '3rdparty/phpass/PasswordHash.php';
class MyDB extends SQLite3
{
function __construct()
{
$this->open('data/owncloud.db');
}
}
$salt = 'put the salt here';
$forcePortable = (CRYPT_BLOWFISH!=1);
$hasher = new PasswordHash(8, $forcePortable);
$user = $_POST['username'];
$pass = $_POST['password'];
$hash = $hasher->HashPassword($pass.$salt);
$db = new MyDB();
$db->query("INSERT INTO oc_users (uid,displayname,password) VALUES ('$user','$user','$hash')");
echo "User created";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment