Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,950 questions

51,892 answers

573 users

How to generate a random password in JavaScript

1 Answer

0 votes
function generatePassword(password_length) {
    const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!$()";
    let password = "";
    let charset_len = charset.length;
     
    for (let i = 0; i < password_length; i++) {
        password += charset.charAt(Math.floor(Math.random() * charset_len));
    }
     
    return password;
}
  
console.log(generatePassword(10));
  
  
  
/*
run:
  
atG2$!xkM$
  
*/

 



answered Dec 21, 2024 by avibootz
edited Dec 21, 2024 by avibootz

Related questions

1 answer 84 views
1 answer 85 views
1 answer 69 views
1 answer 71 views
3 answers 124 views
124 views asked Dec 22, 2024 by avibootz
2 answers 93 views
93 views asked Dec 21, 2024 by avibootz
1 answer 74 views
74 views asked Dec 21, 2024 by avibootz
...