# How-to Generate Complex Passwords?

**URL:** <https://community.postman.com/t/how-to-generate-complex-passwords/41042>\
**Category:** Help Hub\
**Tags:** password, faker-library\
**Created:** [November 11, 2022, 10:48pm UTC](https://community.postman.com/t/how-to-generate-complex-passwords/41042 "2022-11-11T22:48:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![h2oearth](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/h2oearth/32/13898_2.png) [@h2oearth](https://community.postman.com/u/h2oearth)\
**Post date:** [November 11, 2022, 10:48pm UTC](https://community.postman.com/t/how-to-generate-complex-passwords/41042/1 "2022-11-11T22:48:45Z")

</div>

Hi Everyone!

I need to generate random passwords with random lengths (5-80 characters) with the following properties:

- Minimum of 1 lowercase letter [a-z]
- Minimum of 1 uppercase letter [A-Z]
- Minimum of 1 numeric character [0-9]
- Minimum of 1 special character: ~`!@#$%^&\*()-\_+={}|;:"\<\>,./?

Unfornatually, the Faker Dynamic Variable **$randomPassword** (A random 15-character alpha-numeric password) does not provide the flexibility I require!

I tried using an old CDN, but I got the following error " **There was an error in evaluating the Pre-request Script:Error: Maximum call stack size exceeded"**

window = {};  
pm.sendRequest(“[https://cdnjs.cloudflare.com/ajax/libs/Faker/3.1.0/faker.min.js](https://cdnjs.cloudflare.com/ajax/libs/Faker/3.1.0/faker.min.js)”, (error, response) =\> {  
if (error || response.code !== 200) {  
pm.expect.fail(‘Could not load external library’);  
}

```
eval(response.text());

const randomPasswordLength = _.random(5, 80);

window.faker.locale="en";
pm.environment.set("randomPassword", window.faker.internet.password(randomPasswordLength, false, /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]/));

```

});

I do not think I am the first one trying to generate complex passwords. Do you use other CDN or code the required functions in the Pre-request Scripts?

Looking forward to hearing from the postman crew 🙂

---

<div class="post-metadata">

**Author:** ![h2oearth](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/h2oearth/32/13898_2.png) [@h2oearth](https://community.postman.com/u/h2oearth)\
**Post date:** [November 11, 2022, 11:20pm UTC](https://community.postman.com/t/how-to-generate-complex-passwords/41042/2 "2022-11-11T23:20:40Z")

</div>

I guess I found an easy/fast approach [API - Make Me a Password](https://makemeapassword.ligos.net/api) 🙂

---

<div class="post-metadata">

**Author:** ![michaelderekjones](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/michaelderekjones/32/14819_2.png) [@michaelderekjones](https://community.postman.com/u/michaelderekjones)\
**Post date:** [November 16, 2022, 11:55am UTC](https://community.postman.com/t/how-to-generate-complex-passwords/41042/3 "2022-11-16T11:55:34Z")

</div>

@h2oearth

Relying on a third-party API to generate your passwords for you seems excessive.

What happens if that API is down?

Postman uses JavaScript under the hood, so you just need search for one.

A quick search and looking at one of the first results.

[javascript password generator - Stack Overflow](https://stackoverflow.com/questions/1497481/javascript-password-generator)

There are a few options in that link.

This snippet looks good enough for your requirement.

```auto
const Allowed = {
    Uppers: "QWERTYUIOPASDFGHJKLZXCVBNM",
    Lowers: "qwertyuiopasdfghjklzxcvbnm",
    Numbers: "1234567890",
    Symbols: "!@#$%^&*"
}

const getRandomCharFromString = (str) => str.charAt(Math.floor(Math.random() * str.length))
const generatePassword = (length = 8) => { // password will be @Param-length, default to 8, and have at least one upper, one lower, one number and one symbol
    let pwd = "";
    pwd += getRandomCharFromString(Allowed.Uppers); //pwd will have at least one upper
    pwd += getRandomCharFromString(Allowed.Lowers); //pwd will have at least one lower
    pwd += getRandomCharFromString(Allowed.Numbers); //pwd will have at least one number
    pwd += getRandomCharFromString(Allowed.Symbols);//pwd will have at least one symbolo
    for (let i = pwd.length; i < length; i++)
        pwd += getRandomCharFromString(Object.values(Allowed).join('')); //fill the rest of the pwd with random characters
    return pwd
}

```

---

<div class="post-metadata">

**Author:** ![ravip21662](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@ravip21662](https://community.postman.com/u/ravip21662)\
**Post date:** [April 25, 2023, 12:21pm UTC](https://community.postman.com/t/how-to-generate-complex-passwords/41042/4 "2023-04-25T12:21:57Z")

</div>

> **[Secure Your Online Accounts with our Password Generator Tool | Generate...](https://randompasswordgenerators.org/)**
>
> Create strong, secure passwords with our password generator tool. Protect your personal and financial information from cyber threats by using our customizable password generator.

here you can check for how can i generate password using single click  
using jquery you can made it your own[password generator](https://randompasswordgenerators.org/)
