Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Text
Posted by: Amit Sarker
Added: Feb 25, 2018 10:30 AM
Modified: Feb 25, 2018 10:31 AM
Views: 8
Tags: no tags
  1. //php
  2. function generate_random_password() {
  3.     $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
  4.     $pass = array(); //remember to declare $pass as an array
  5.     $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
  6.     for ($i = 0; $i < 8; $i++) {
  7.         $n = rand(0, $alphaLength);
  8.         $pass[] = $alphabet[$n];
  9.     }
  10.     return implode($pass); //turn the array into a string
  11. }
  12. //php
  13.  
  14. //Jquery
  15. $('#generate_password_button').on('click', function () {
  16.             var password = "";
  17.             password = generate_random_password();
  18.             $('#generate_password_label').text(password);
  19.             $('#password').val(password);
  20.             $('#confirm_password').val(password);
  21.         });
  22.  
  23.         function generate_random_password() {
  24.             var chars = "abcdefghijklmnopqrstuvwxyz!@#$%^&*()-+<>ABCDEFGHIJKLMNOP1234567890";
  25.             var password = "";
  26.             for (var x = 0; x < 8; x++) {
  27.                 var i = Math.floor(Math.random() * chars.length);
  28.                 password += chars.charAt(i);
  29.             }
  30.             return password;
  31.         }
  32. //Jquery