Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 )

share|improve this question

1 Answer 1

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.")));
            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).

share|improve this answer
thanks (: I already solved the problem by using the imap backend as I have a mail server accesing the same database anyway. But if I find the time to write the hook then I'll post my results here. (PS: sorry, I can't vote you up, still new here ^^ ) – ciem Jun 24 '14 at 11:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.