# Username string into PLC tag

**URL:** <https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157>\
**Category:** Ignition\
**Created:** [June 22, 2015, 9:25pm UTC](https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157 "2015-06-22T21:25:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ESE-CE](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@ESE-CE](https://forum.inductiveautomation.com/u/ESE-CE)\
**Post date:** [June 22, 2015, 9:25pm UTC](https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157/1 "2015-06-22T21:25:32Z")

</div>

How do I get the current username written into a PLC tag?  
I’m using ControlLogix and Studio 5000 21.03

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [June 22, 2015, 10:15pm UTC](https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157/2 "2015-06-22T22:15:45Z")

</div>

Write a Client Startup Script that writes the username to the PLC tag using the [system.tag.write() function](https://support.inductiveautomation.com/usermanuals/ignition/index.html?system_tag_write.htm).

Use the system.security.getUsername() function to get the username of the logged in user.

Best,

---

<div class="post-metadata">

**Author:** ![ESE-CE](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@ESE-CE](https://forum.inductiveautomation.com/u/ESE-CE)\
**Post date:** [June 23, 2015, 12:12pm UTC](https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157/3 "2015-06-23T12:12:23Z")

</div>

That makes sense. hank you.  
I’m not a script writer. Any way you could show me what that script might look like?  
Thanks

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [June 23, 2015, 1:33pm UTC](https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157/4 "2015-06-23T13:33:21Z")

</div>

`user = system.security.getUsername()
system.tag.write("PathToYourTag",user)`

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [June 23, 2015, 2:50pm UTC](https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157/5 "2015-06-23T14:50:41Z")

</div>

Here’s a video about Startup Scripts: [inductiveuniversity.com/video/startup-scripts](https://inductiveuniversity.com/video/startup-scripts)

Best,

---

<div class="post-metadata">

**Author:** ![ESE-CE](https://avatars.discourse-cdn.com/v4/letter/e/898d66/32.png) [@ESE-CE](https://forum.inductiveautomation.com/u/ESE-CE)\
**Post date:** [June 23, 2015, 3:09pm UTC](https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157/6 "2015-06-23T15:09:34Z")

</div>

Thanks  
This is what my script looks like:  
#Define Tech password as “1234”

# Get the username from the System

#If the user is logged in as Tech, write “1234” to the PLC tag  
#Write a “0” otherwise  
Techpassword=1234  
Username = system.security.getUsername()  
if Username == ‘Tech’:  
system.tag.write("[{PLC}]BAT\_HMI/BAT\_HMI.Code",Techpassword)  
else:  
system.tag.write("[{PLC}]BAT\_HMI/BAT\_HMI.Code",0)

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [June 23, 2015, 3:55pm UTC](https://forum.inductiveautomation.com/t/username-string-into-plc-tag/10157/7 "2015-06-23T15:55:25Z")

</div>

This kind of security will get you in big trouble if there’s any chance for multiple clients opening this project. If one client opens it and is not ‘Tech’, then another client opens it simultaneously as ‘Tech’, the PLC will be in ‘Tech’ mode for both. If the tech opens first, he/she will lose tech access when the second client logs in.

You should not use a PLC global tag to control security for Ignition clients. Use Ignition’s security system. If you have a fixed location for a client that should have different default behaviors, check the client IP address or some other reliable indicator of that location then preset Ignition’s security using system.security.switchUser().
