Jump to content

Cum Generez Aleatoriu O Parola Cu Ajutorul Php


Recommended Posts

Posted

Aveti mai jos, un mic scriptulet PHP, care va genera aleatoriu (la intamplare) o parola. Scriptul ofera o singura optiune de complexitate, si anume numarul de caractere ce alcatuiesc parola.

Codul de mai jos, va crea ceva de genul:

parolaaaaaaaaaaaaaaaaaa.png

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>PC Troubleshooting - Generate random password</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta content="robots" name="noindex,nofollow" />

<style type="text/css">
<!--
* {
   margin:0;
   padding:0;
}

#generate {
   border:none;
   background:#333;
   color:#ccc;
}

#table {
   margin:0 auto;
}
-->
</style>

</head>
<body>

<!–-generez dinamic URL`ul absolut al paginii curente.
Catre ea vor fi transferate datele din formular dupa ce se va apasa butonul submit-–>
<form action="<?php echo 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']; ?>" method="post">
<table cellspacing="5" border="0" cellpadding="0" id="table">
   <tr>
       <td>
           <strong>numarul de caractere: </strong>
       </td>

       <td>
           <select name="numar_caractere" style=" width:50px;">
           <?php
           //restrictionez numarul de caractere pe care il poate avea parola (minim 5 caractere si maxim 20 de caractere)
           $numar = range(5,20);
           foreach ($numar as $item) {
               echo '<option>'.$item.'</option>';
           }
           ?>
           </select>
       </td>
   </tr>

   <tr>
       <td>
           <strong>parola: </strong>
       </td>

       <td>
       <?php
       //scriptul se va executa DOAR DACA se va apasa pe butonul submit
       if (isset($_POST['generate'])) {
           //creez array`ul ce contine caracterele ce vor alcatui parola
           $caractere = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
                              'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
                              'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
                              'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
                              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',  
                              '!', '@', '#', '$', '%', '^', '{', '*', '(', ']',
                              '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',  
                              '!', '@', '#', '$', '%', '^', '{', '*', '(', ']');

           //generez aleatoriu parola
           $i = 0;
           while ($i < $_POST['numar_caractere']) {
               echo $caractere[rand(0,(count($caractere) - 1))];
               $i++;
           }
       }
       ?>
       </td>
   </tr>

   <tr>
       <td>
           &nbsp;
       </td>

       <td>
           <input name="generate" type="submit" id="generate" value="generate" />
       </td>
   </tr>
</table>
</form>

</body>
</html>[/code]

[color=gray][i]Acest script PHP este realizat de AccesInterzis.[/color][/i]

Succes :pct:

Te-ai inregistrat? Ne-ar placea sa te prezinti.

Cum pot sustine forumul?
Cumpara de la eMag folosind acest link.
--------------------
oG2BN9d.gifse1WdXd.gifQG6MtmI.gifRHYjDzD.gifG5p1wui.gif

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.