owncloud with pre-existing user database

I have a setup of dovecot with virtual users in a database. Now I would like to set up owncloud using the same users as already in the database. Is it somehow possible to configure owncloud as such one can log in only with the username and password from my existing database? Do you maybe know of a tutorial, that does that? (I couldn’t find neither explanations on that nor a tutorial.)

The database has two columns, one with the user, one with the hashed password (sha512-crypt, with the normal format of mysql: $6$salt$hash )

Answer

As far as I can tell you can’t use the external user database directly. However, it should be possible to use a hook that accesses the user database in a login attempt.

This post from the owncloud form shows how the hook pre_login is used. It checks for an LDAP group, but this should be easily adapted to your case.

Copy&paste of the essentials from the post:

Create a function that does the lookup in your database and returns true when the user is valid.

File <owncloud>/apps/<your_plugin>/appinfo/hooks.php

OC::$CLASSPATH['OC_Templates'] = 'lib/util.php';
class OC_user_ldap_Hooks{

public static function IsUserInGroup($parameters) {
            // replace this with your own database logic
            $filter = "(&(cn=owncloudusers)(memberUid=".$parameters['uid']."))";
           if(!OC_LDAP::searchGroups($filter, 'dn') && $parameters['uid']!="admin")
            {
                    $tmpl = new OC_Template( '', 'error', 'guest' );
                    $tmpl->assign('errors',array(1=>array('error'=>"User <b>".$parameters['uid']."</b> is not a member of a group allowed to login.")));
                    $tmpl->printPage();
                    exit;
            }
            return true;
    }
}

And in the file <owncloud>/apps/<your_plugin>/appinfo/app.php

OC::$CLASSPATH['OC_user_ldap_Hooks'] = 'apps/<your_plugin>/lib/hooks.php';
OCP\Util::connectHook('OC_User', 'pre_login', 'OC_user_ldap_Hooks', 'isUserInGroup')

This is just the basic to get you started, you will have to handle a little more (for example creation of a new user in ownCloud if a user logs in the first time).

Attribution
Source : Link , Question Author : Tim , Answer Author : Gerald Schneider

Leave a Comment