# Check if an user is already present with same email id

**URL:** <https://forum.inductiveautomation.com/t/check-if-an-user-is-already-present-with-same-email-id/58411>\
**Category:** Ignition\
**Created:** [April 13, 2022, 12:52pm UTC](https://forum.inductiveautomation.com/t/check-if-an-user-is-already-present-with-same-email-id/58411 "2022-04-13T12:52:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.inductiveautomation.com/u/user66)\
**Post date:** [April 13, 2022, 12:52pm UTC](https://forum.inductiveautomation.com/t/check-if-an-user-is-already-present-with-same-email-id/58411/1 "2022-04-13T12:52:40Z")

</div>

I’m trying add a new user but before adding I need to check if an user is already present with the same email address. How can this be achieved?  
eg:

```auto
userToGet = system.user.getNewUser("AcmeWest", "mTrejo")
  
# Add some contact info
contactInfo = {"email":"mTrejo@acmewest.com","sms": "5551234"}
userToGet.addContactInfo(contactInfo)
userToGet.set("password", "thisIsMyPassword")
 
# Adds a user to the the AcmeWest usersource.
system.user.addUser("AcmeWest", userToGet)

```

I need to check if there already exists an user with [email:"mTrejo@acmewest.com](mailto:email:%22mTrejo@acmewest.com)"

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 13, 2022, 1:50pm UTC](https://forum.inductiveautomation.com/t/check-if-an-user-is-already-present-with-same-email-id/58411/2 "2022-04-13T13:50:59Z")

</div>

You would need to iterate through the existing users, and look at each contactInfo:

```python
# Get users from the usersouce
users = system.user.getUsers('AcmeWest')

emailExists = False

for user in users:
	# Get contact info for the user
	contactInfo = user.getContactInfo()
	for item in contactInfo:
		# Check if a matching email exists
		if item.getContactType() == 'email' and item.getValue() == 'mTrejo@acmewest.com':
			emailExists = True
	# Break out of the loop if we find a match
	if emailExists:
		break
		
if emailExists:
	uh_oh()
else:
	do_some_stuff()

```

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.inductiveautomation.com/u/user66)\
**Post date:** [April 14, 2022, 5:40am UTC](https://forum.inductiveautomation.com/t/check-if-an-user-is-already-present-with-same-email-id/58411/3 "2022-04-14T05:40:24Z")

</div>

If I'm trying to edit an user can I give a condition so that it does check the email of the user I'm currently editing?

> [@JordanCClark](#):
>
> `for user in users:`

For that I would need to access the 'username' in user

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [April 14, 2022, 11:59am UTC](https://forum.inductiveautomation.com/t/check-if-an-user-is-already-present-with-same-email-id/58411/4 "2022-04-14T11:59:10Z")

</div>

Since you already have the user, you can use system.user.getUser() to get a single user.

```python
user = system.user.getUser('AcmeWest', 'mTrejo')

emailExists = False

contactInfo = user.getContactInfo()
for item in contactInfo:
	# Check if a matching email exists
	if item.getContactType() == 'email' and item.getValue() == 'mTrejo@acmewest.com':
		emailExists = True
		break
			
if emailExists:
	uh_oh()
else:
	do_some_stuff()

```

---

<div class="post-metadata">

**Author:** ![user66](https://avatars.discourse-cdn.com/v4/letter/u/b487fb/32.png) [@user66](https://forum.inductiveautomation.com/u/user66)\
**Post date:** [April 14, 2022, 12:25pm UTC](https://forum.inductiveautomation.com/t/check-if-an-user-is-already-present-with-same-email-id/58411/5 "2022-04-14T12:25:38Z")

</div>

Yes. That's the method 😇

> [@JordanCClark](#):
>
> `user = system.user.getUser('AcmeWest', 'mTrejo')`

We can use user.get("username") to get the userName
