How to decrypt password 2 type fields ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 02:18 AM
Hi,
I have created 3 fields on form which has type as Password 2.
fields are: 1. Password 2. secret key 3. Auth Key
In Ui action I am validating the credentials of user.So for this I have decrypted the field Password as follow:
var decryptedPassword = g_form.getValue('password').getDecryptedValue();
var data = {
username: trimStr(g_form.getValue('username')),
password: decryptedPassword
};
but the main issue with it is if I am validating the different user next time then authentication get failed.
and how to use all Password 2 type fields inside
var data = {
username: trimStr(g_form.getValue('username')),
password: decryptedPassword
};
please help in this I am getting confused in scripting with decryption.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 02:26 AM
Hi,
please provide some exact requirement or example
You have 3 fields on form then what should be happening?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 02:35 AM
Thanks Ankur for your quick response.
I have created the Configuration form on which I have created 3 fields which are Password 2 type fields as I mentioned above. Which the username and the data from the encrypted field we need to validate the users credentials and once the credentials get validated the user will fetch the data from another platform.
So for validation I have created Ui action as Validate user and in Ui action I need to decrypt the data pf Password 2 type fields.
so for decryption I have used the below script
var decryptedPassword = g_form.getValue('password').getDecryptedValue();
Could you please suggest me how to decrypt all 3 fields and how to use it in structure named as data
var data = {
username: trimStr(g_form.getValue('username')),
password: decryptedPassword
};
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 03:05 AM
Hi,
below is the server side which will decrypt the password;
I don't think using g_form you can decrypt it
Ensure your UI action is server side for below code to work
You can form array of json object for that; you can give your own key name and value name
For example I have taken at all places as "username" and "password'
var Encrypter = new GlideEncrypter();
var arr = [];
var userNameEncrypted = current.user_name; // give proper field name here
var userNameDecrypted = Encrypter.decrypt(userNameEncrypted);
var obj = {};
obj['username'] = userNameEncrypted.toString();
obj['password'] = userNameDecrypted;
arr.push(obj);
var secretKeyEncrypted = current.secret_key_field; // give proper field name here
var secretKeyDecrypted = Encrypter.decrypt(secretKeyEncrypted);
var obj = {};
obj['username'] = secretKeyEncrypted.toString();
obj['password'] = secretKeyDecrypted;
arr.push(obj);
var authKeyEncrypted = current.secret_key_field; // give proper field name here
var authKeyDecrypted = Encrypter.decrypt(authKeyEncrypted);
var obj = {};
obj['username'] = authKeyEncrypted.toString();
obj['password'] = authKeyDecrypted;
arr.push(obj);
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-12-2021 05:23 AM
Hope you are doing good.
Did my reply answer your question?
If so, please mark appropriate response as correct & helpful so that the question will appear as resolved for others who may have a similar question in the future.
Thanks!
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader