Insert new user in database


(Quest) #1

Hey there

I’ve got a small problem:

In my company we have a small tool to manage the accounts of our users in different applications using SQL-statements.
Now my boss wants me to integrate piwik’s user table into this tool.

I tried it using the following mysql statement. Insert into user’s table works, but the created user cannot login (‘Wrong username or password’)

 INSERT INTO piwik_user( login, password, alias, email, token_auth, date_registered )
VALUES (
'user_test', MD5( 'lipiby01' ) , 'A Testuser', 'a.testuser@cadenas.de', MD5( 'user_test' + MD5( 'lipiby01' ) ) , NOW( )
) 

Can you tell me what’s wrong with this statement?

Regards, Michael


(Christian Schneider) #2

Hi Michael

Do you also run a sql statement for the access table (idsite, login, access)?

I don’t know if the + works at the token_auth value in sql, are you sure that it is correct?

Regards,
Christian.


(vipsoft) #3

Did you get an installation warning about mismatched charsets? If so, and you didn’t resolve it, then you should use the API instead of modifying the database directly.


(Matthieu Aubry) #4

The best way to create users is to use the API: UsersManager.addUser (userLogin, password, email, alias = ‘’)


(Quest) #5

@Christian: Thanks for the tipp, mysql has a problam with ‘+’. Using CONCAT instead solves the problem:
INSERT INTO piwik_user( login, password, alias, email, token_auth, date_registered )
VALUES (
‘user_test’, MD5( ‘lipiby01’ ) , ‘A Testuser’, ‘a.testuser@cadenas.de’, MD5( CONCAT( ‘user_test’, MD5( ‘lipiby01’ ) ) ) , NOW( )
)