security module: allow update username

Hello, anybody tried to make it possible to edit username when using SC security module, currently i can’t update the username, only password and other name, email…etc… also can’t see this login field that is for read only or as label… nothing, how to control this and any other change required to make it possible to be able to update the username? i know many tables should be updated, not only the users table… like users_groups or table users…

did you try this?

username or login?

username and login are the same dear

if your user logged table is user_logged and the user table is user_users then issue this SQL command:(mySql only)
Alter table user_logged
Drop FOREIGN KEY user_logged_ibfk_1,
Add FOREIGN KEY (login) REFERENCES user_users(login) on delete cascade on update cascade;

++++++++++++++++++++
For n time issue of the command change user_logged_ibfk_n!
:slight_smile:

hello rajibul
thank you but i think you didn’t get my question, it is not related to logged users, I don’t use logged users function
now using scriptcase security module, I want to be able to edit users and to be able to edit their usernames as well (login) not only their name, email and password

The rajibul’s solution works fine Mike,

if you are using group based security may be the following works

/MYSQL/
ALTER TABLE database.sec_users_groups DROP FOREIGN KEY users_groups_fkey; – drop the foreign key
ALTER TABLE database.sec_users_groups ADD CONSTRAINT users_groups_fkey
FOREIGN KEY (login) REFERENCES database.sec_users(login) ON UPDATE CASCADE ON DELETE NO ACTION; – recreate the contraint

Dear Mike, The solution must work for you without any fail! Please check and confirm.
The architecture for SC security module’s user table is linked with user logged (user and logged user table automatically created by SC) table, I.e., if there is any login history for the user then it restrict the renaming of login fields in user table, hope u understand now.

Thanks.

Oh! you mean to remove the foreign key chain then will be able to adjust the usernames and edit them? will not that affect anything else?

The only way is to drop the constraints (temporarely), then update the keys in the main table and foreign tables, then enable the constraint again. On MySQL something like:

 
 - Disable the constraints on a table called tableName: ALTER TABLE tableName NOCHECK CONSTRAINT ALL  -- Re-enable the constraints on a table called tableName: ALTER TABLE tableName WITH CHECK CHECK CONSTRAINT ALL ---------------------------------------------------------  -- Disable constraints for all tables: EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"  -- Re-enable constraints for all tables: EXEC sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"

Actually i would have used another design. They should have used a autosequence for the reference and a username as attribute using a unique index.

Albert I see this too complicated or didn’t understand it well, now i have like many users want to edit and change their usernames, I want to know what is the consequences, still don’t know why this temporarily and until when i should consider keep them dropped or what is next or what is the risk, i was planning to remove and create them again from beggning but any more details on what to do and how to drop or when to reenable the constraint then i appreciate the help thank you

Mike, the most simple way is to drop the foreign keys and manage them manually. Then you can safely update the username if you apply that to the childs tables too. Scriptcase cannot change the primary key as it generates the wrong sql for that so you need to create a small control with fields and write your own program.
Be aware that the casade delete will not work any more, so there are pitfalls. You need to write more management code.

thanks Albert