← Back to team overview

dhis2-devs team mailing list archive

Re: Automatically mass-generate dhis2 usernames and passwords

 

Thanks for this. Looks very useful. Another way to do this (which I have
mentioned before on the list, is with R). Here are a couple of  R code
fragments which I think I have sent previously.

#Generate the Java Hash Code. R does not calculate this properly, so we
have to revert to using Java for now.
javaHashCode<-function(string="") {
require(rJava)
.jinit()
s <- .jnew("java/lang/String", string)
.jcall(s,"I","hashCode") }

#Start to generate the encrypted passwords
genEncryptedPass<-function(password="district",username="admin") {
#This is needed for the digest function
require(digest)
digest(paste0(password,"{",javaHashCode(username),"}"),serialize=FALSE) }

#Start to build up the data frame here
result<-as.data.frame(cbind(usernames,passwords),stringsAsFactors=FALSE)
result$encrypt<-mapply(genEncryptedPass,password=result$passwords,username=result$usernames)

So, with these two basic functions (javaHashCode and genEncryptedPass), you
can generate the meat of what you need. If you have a list of usernames and
passwords (which of course can also be generated in R) in a dataframe
called "result", the last line will give you the encrypted password.

Using SQL, you can then generate of course some insert statements or DXF to
import into DHIS2. If anyone needs more code for this, I can provide some
more details. I suspect the same thing could be easily done with other
scripting languages as well.

I think these Java classes will help but would suggest to abstract out
these methods a bit as right now, the DB connection is hard coded?

Regards,
Jason



On Fri, Jul 5, 2013 at 4:26 PM, Ngoc Thanh Nguyen <
thanh.hispvietnam@xxxxxxxxx> wrote:

> In case you need to expedite creation of thousands of users and passwords
> the following classes might help. In essence, all of user creation steps
> can be done by sql. However, password hash is a bit tricky in dhis2 when it
> depends on Spring Security.
>
>
> https://dl.dropboxusercontent.com/u/63702128/dhis2%20user%20generator/GeneratePassword.java
>
> https://dl.dropboxusercontent.com/u/63702128/dhis2%20user%20generator/RandomGenerator.java
>
> After having a list of username and password pairs you can use sql to fill
> in users and userinfo tables, plus other germane tables for assigning
> orgunit and roles.
>
> Thanh
>
> _______________________________________________
> Mailing list: https://launchpad.net/~dhis2-devs
> Post to     : dhis2-devs@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~dhis2-devs
> More help   : https://help.launchpad.net/ListHelp
>
>

Follow ups

References