How to reset Cyclos 4 admin password?

If you lost your Cyclos 4 admin password you may be in troubles. To recover (by reset) access to your Cyclos 4 administration panel follow the tutorial.

The instructions that can be found in the net refer to Cyclos 3 and they will not work with Cyclos 4 that has been rewritten quite substantially. Here are steps for Cyclos 4.1 and above:

1. Login to your account via SSH and go to cyclos directory (usually webapps/ROOT or webapps/cyclos in your Tomcat’s directory tree defined with $CATALINA_HOME)

2. Get your cyclos database credentials (example). You will need them to make changes to the database

grep -E 'datasource.(jdbc|user|pass)' WEB-INF/classes/cyclos.properties 
cyclos.datasource.jdbcUrl = jdbc:postgresql://localhost/cyclos4_cyclosdb
cyclos.datasource.user = cyclos4_cyclosdbuser
cyclos.datasource.password = secret

3. Get your admin user’s salt from the database

echo "select user_id, u.username, p.salt, p.status from passwords p, users u where u.id=p.user_id and u.username = 'admin'" | psql -U cyclos4_cyclosu -d cyclos4_cyclos
Password for user cyclos4_cyclosu:
 user_id | username |               salt               | status
---------+----------+----------------------------------+--------
       1 | admin    | gCimTuCV1Fw7J2AsefoXDRfMy47vxzAB | ACTIVE
(1 row)

4. Save and compile hash generator – we will use it to compute has for our new password

cat > GenerateCyclos4PasswordHash.java <<EOF
import org.cyclos.impl.utils.HashHelper;

public class GenerateCyclos4PasswordHash {
    public static void main(String[] args) {
        if (args.length < 2) {
            System.err.println("2 parameters required: existing_salt and new_password");
            System.exit(1);
        } else {
            String h = HashHelper.hash(args[0], args[1]);
            System.out.println("You may now set the new password by accessing your Cyclos 4 (PostgreSQL) database and running:");
            System.out.println("update passwords set value = '"+h+"' where username='admin' and status='ACTIVE';");
        }
    }
}
EOF

javac -classpath WEB-INF/lib/cyclos-impl.jar GenerateCyclos4PasswordHash.java

This will create class file in current directory.

5. Run the hash generator prviding existing admin salt and new admin password as parameters 

java -classpath WEB-INF/lib/cyclos-impl.jar:. GenerateCyclos4PasswordHash gCimTuCV1Fw7J2AsefoXDRfMy47vxzAB newsecret

You may now set the new password by running below command against your Cyclos 4 (PostgreSQL) database (use the value produced by the generator):

echo "update passwords set value = '5F89C071A59DBAC17AA59F49D9473226947D900491B48DD57B18E2B37EBD0101' where username='admin' and status='ACTIVE';" | psql -U cyclos4_cyclosu -d cyclos4_cyclos

You should now be able to login as admin with ‘new secret’ password.

Note for older Cyclos versions like 4.0.1
1) The jar may be called cyclos-impl-4.0.1.jar – use proper jar name in javac and java calls
2) The HashHelper class is named ‘i’ and the hash function is named ‘e’ so in the java code use:

import org.cyclos.impl.utils.i;
String h = i.e(args[0], args[1]);

This entry was posted in Java, Tomcat. Bookmark the permalink.

2 Responses to How to reset Cyclos 4 admin password?

  1. Gertjan van Hardeveld says:

    Thanks for the tutorial.
    I am really new at this so sorry if these are n00b questions.
    at step 5 you tell me to enter

    “update passwords set value =
    ‘5F89C071A59DBAC17AA59F49D9473226947D900491B48DD57B18E2B37EBD0101′ where
    username=’admin’ and status=’ACTIVE';” | psql -U cyclos4_cyclosu -d
    cyclos4_cyclos

    whenn I do I get a “column “username” does not exist” please help

    • admin says:

      1. Make sure your database name is correct (it is usually not the same as in the example)
      2. Make sure the database structure has been correctly auto created by Cyclos
      For Cyclos 4 it looks as below (username column is present)

      Cyclos 4 (PostgreSQL)

      cyclos=# \d users;
                                                Table "public.users"
              Column        |            Type             |                     Modifiers                      
      ----------------------+-----------------------------+----------------------------------------------------
       id                   | bigint                      | not null default nextval('users_id_seq'::regclass)
       subclass             | character varying(31)       | 
       creation_date        | timestamp without time zone | not null
       email                | character varying(255)      | 
       last_login           | timestamp without time zone | 
       name                 | character varying(100)      | not null
       new_email            | character varying(255)      | 
       username             | character varying(255)      | not null
       version              | integer                     | not null
       user_activation_date | timestamp without time zone | 
       user_hide_email      | boolean                     | 
       status               | character varying(255)      | 
       validation_date      | timestamp without time zone | 
       validation_key       | character varying(255)      | 
       user_group_id        | bigint                      | 
       user_activity_id     | bigint                      | 
       name_tsvector        | tsvector                    | 
       username_tsvector    | tsvector                    | 
       email_tsvector       | tsvector                    | 
      

Leave a Reply

Your email address will not be published. Required fields are marked *


seven × = thirty five

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>