{"id":89,"date":"2022-01-03T12:08:32","date_gmt":"2022-01-03T12:08:32","guid":{"rendered":"https:\/\/ionicframeworktraining.com\/blogs\/?p=89"},"modified":"2022-05-13T11:55:01","modified_gmt":"2022-05-13T11:55:01","slug":"how-to-create-strong-password-in-javascript-with-number-alphabet-and-symbols","status":"publish","type":"post","link":"https:\/\/meanjstraininginstitute.com\/blogs\/2022\/01\/03\/how-to-create-strong-password-in-javascript-with-number-alphabet-and-symbols\/","title":{"rendered":"How To Create Strong Password In JavaScript With Number, Alphabet And Symbols."},"content":{"rendered":"<p><strong>Step1:-<\/strong> Add textbox to display Password<\/p>\n<p>&lt; input type=&#8221;text&#8221; id=&#8221;password&#8221; &gt;<\/p>\n<p><strong>Step2:-<\/strong> Declare variable and regular expression pattern<\/p>\n<p>var allChars = &#8220;0123456789abcdefghijklmnopqrstuvwxyz!@#$%^&amp;*()ABCDEFGHIJKLMNOPQRSTUVWXYZ&#8221;;<br \/>\nvar pwd= &#8220;&#8221;;<br \/>\nvar pattern = new RegExp(&#8220;^(?=.*[a-z])(?=.*[A-Z])(?=.*\\\\d)(?=.*[-+_!@#$%^&amp;*.,?]).+$&#8221;);<\/p>\n<p><strong>Step3:-<\/strong> Create generatePassword function and check password validation<\/p>\n<p>function generatePassword() {<br \/>\nfor (var i = 0; i &lt;= 8; i++) {<br \/>\nvar randomNumber = Math.floor(Math.random() * allChars.length);<br \/>\npwd += allChars.substring(randomNumber, randomNumber +1);<br \/>\n}<br \/>\nif(pattern.test(pwd)){<br \/>\ndocument.getElementById(&#8220;password&#8221;).value = pwd;<br \/>\n} else {<br \/>\npwd=&#8221;&#8221;;<br \/>\ngeneratePassword();<br \/>\n}<br \/>\n}<\/p>\n<p>generatePassword();<\/p>\n<p><strong>Step4:-<\/strong> Add button to copy strong password<\/p>\n<p>&lt; button onclick=&#8221;copyPassword()&#8221; &gt;Copy&lt; \/button&gt;<\/p>\n<p><strong>Step5:-<\/strong> Create function to copy generated password<\/p>\n<p>function copyPassword(){<br \/>\ndocument.getElementById(&#8220;password&#8221;).select();<br \/>\ndocument.execCommand(&#8220;copy&#8221;);<br \/>\n}<\/p>\n<p>Example:-<br \/>\n<input id=\"password\" type=\"text\" \/> <button onclick=\"copyPassword()\">Copy<\/button><button style=\"margin-left:1rem\" onclick=\"resetPassword()\">Reset<\/button><\/p>\n<p><script src=\"https:\/\/meanjstraininginstitute.com\/js\/posts.js\"><\/script><\/p>\n","protected":false},"excerpt":{"rendered":"<p>How To Create Strong Password In JavaScript With Number, Alphabet And Symbols.<\/p>\n","protected":false},"author":1,"featured_media":90,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":21,"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"predecessor-version":[{"id":119,"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/posts\/89\/revisions\/119"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/media\/90"}],"wp:attachment":[{"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meanjstraininginstitute.com\/blogs\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}