Invite users to log to your App sending email with auto-generated PW

1/ In users object add a text field called "autogenerated password"

in the following example field ID is #field_10.

2/ Create a form based on users

with at least name and email + the autogenerated password : in the following example the form ID is #view_20.

3/ in the form rule / record rule

create the following rule :

Update this record

Set "password" to "a form value", "autogenerated password"

4/ Create an email rule

"send a custom email"

send "to" "an email field" "Email"


write your text and select the field from the left hand list:

your ID: {Email}

your password: {Auto generated password}

5/ Add the following codes to API and code / Javascript

this function generates the random PW

/*Generate random password*/

$.generateRandomPassword = function(limit) {
limit = limit || 8;
var password = ‘’;
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789><!"$%&/()=?#_-@+’;
var list = chars.split(’’);
var len = list.length, i = 0;
do {
i++;
var index = Math.floor(Math.random() * len);
password += list[index];
} while(i < limit);
return password;
};

and then the following to call the function and disable the field to prevent the autogenerated PW to be modified in the form.

/ generates random PW in the form and disable the field to prevent modification*/

$(document).on(‘knack-view-render.view_20’, function (event, view, data) {
var pwd = $.generateRandomPassword(8);
$(’#field_10’).val(pwd).prop(‘disabled’, true);
});

5/ Add the following codes to API and code / CSS

To grant confidentiality of the auto generated PW this will replace the PW characters by dots in your interface.

/* replace the PW characters by dots */

#field_10 {
-webkit-text-security: disc;
}


Native solution which works for my workflow.

I have workflow with two step new Client creation:

1) First a user record is created and User Status left to "Pending Approval" - this could be done by any user with "Client" Role

2) Then, the user with "Account Manager" Role has to approve the new created account.

This gives the possibility to use Knack build in function random()

I have created text formula field "Autogenerated Password" = random(8)

I have created second text field "Initial Password"

Then when the "approval" form is submitted I have a submit rule which sets the value of "Initial Password" to "Autogerated Password" and "Password" to "Initial Password". Next I have an Email template with login data and "Initial Password".

In the case you are wondering why I am using this additional "Initial Password" field - it is because text formula is recalculated after the Submit and before Email rule, so in Email template I cannot use text formula field.

Andrzej

Thanks!

Thanks Steven! This is exactly what I needed!

Omar, if it's any reassurance neither am I other than being a self taught MS Access developer in-house. Using Knack has meant starting to learn CSS & Javascript which is great, and probably deserves a forum post on it's own.

Quick tips to dive in:

  • Try new things in a test app - don't break something you use in production.
  • Chrome inspection window is your friend - catch errors in Javascript and try in-line CSS changes, use the copy Selector to get your CSS working.

Steven - thanks again for this, it's meant inviting users to an app a lot easier.

Can you do this natively in knack?

use the new equation functions recently introduced-- randINT to pull a random integer or something? multiply that randtom integer by another random INT?

set PW equal to the new super random INT?

I dunno-- I just get nervous when considering to mess with code bc I have no programming background.

thanks - true that my org uses only Chrome

Minor tweak - our users are majority Internet Explorer types and that browser doesn't recognise CSS webkit styles. Found this tweak to Steven's Javascript does the job on Chrome & IE (can't test on others right now) and then doesn't require a CSS entry:

$(document).on('knack-view-render.view_20', function (event, view, data) {
    var pwd = $.generateRandomPassword(8);
    $('#field_10').val(pwd).prop('disabled', true);
    $('#field_10').prop('type', 'password');
});

Thanks again for sharing Steven.