- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 09:04 AM
Hello,
As part of a requirement for creating certain users we have a form which asks for a password that upon submission is encrypted using GlideEncrypter().
The problem is when I try to decrypt the value and set it as the password it is not working correctly as the decrypted value does not work as the password.
Below is the code I use to decrypt and set the password.
var Encrypter = new GlideEncrypter();
var decrypted = Encrypter.decrypt(current.variables.password);
var gu = new GlideRecord('sys_user');
gu.initialize();
gu.user_name = current.variables.headless_id;
gu.first_name = current.variables.headless_id;
gu.last_name = current.variables.headless_id;
gu.email = current.variables.email_address;
gu.user_password.setDisplayValue(decrypted.toString());
//gu.user_password.setDisplayValue(decrypted);
//gu.user_password.setValue(decrypted);
gu.user_password.setDisplayValue(decrypted.toString());
gu.insert();
If I do not encrypt the password this script works fine though.
Any thoughts on this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-27-2015 07:28 PM
Hi Alexander,
The problem is that line 2 above sets the decrypted variable as what I am assuming is a Java string. Calling toString on that object, likewise, returns another string. If you do a typeof decrypted it will return "object" and not 'string'. The setDisplayValue function expects a string and apparently has no idea how to handle the object it is given. The solution is to add + '' which forces a type conversion to a javascript string that setDisplayValue can use. Thus, the following function should work for you:
var Encrypter = new GlideEncrypter();
var decrypted = Encrypter.decrypt(current.variables.password);
var gu = new GlideRecord('sys_user');
gu.initialize();
gu.user_name = current.variables.headless_id;
gu.first_name = current.variables.headless_id;
gu.last_name = current.variables.headless_id;
gu.email = current.variables.email_address;
gu.user_password.setDisplayValue(decrypted + '');
gu.insert();
I hope this helps.
Kind regards,
Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-23-2015 09:36 AM
Here is my script for the business rule on the incident table
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var Encrypter = new GlideEncrypter();
var decrypted = Encrypter.decrypt(current.u_encrypted_password);
var gu = new GlideRecord('incident');
gu.initialize();
gu.u_encrypted_password.setDisplayValue(decrypted + '');
gu.insert();
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-24-2017 12:25 AM
In my demo Instance, when I am trying to print the password field (from sys_user table), it is showing a decrypted value.
1) I would like to know
which script/BR is responsible for converting password ...into decrypted value.
2) As a admin user if I want to print all the password values, --> how should i approach this...
Note: The above questions are only to enhance my knowledge
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-27-2017 06:48 PM
Is it possible to use GlideEncrypter() in workflow run script activities? So far no luck. Wondering if I need to reference a full package name of some sort?