aver como puedo hacer que en los campos de usuario y password
genere automatico un usuario y password
| |||
Respuesta: tengo un formulario de usuario y password <td width="350" height="15"> <form id="adduser" name="adduser" action="adduser.php" method="post"> <?php if (isset($_POST["username"]) and $_POST["badduser"] == "Add user and stay" and $userexists == "false" and $nouserpass == "false" and $clearfields == "false" and $createpassword == "false") { print("<font color=\"#347C2C\">User ".$_POST["username"]." successfully added!</font><br><br>"); } if ($userexists == "true" and $createpassword == "false") { print("<font color=\"#FF0000\">El Usuario ya Existe!</font><br><br>"); } if ($nouserpass == "true") { print("<font color=\"#FF0000\">Debe introducir un nombre de usuario y una contraseña!</font><br><br>"); } ?> Nombre:<br> <input type="text" name="username" size="20" tabindex="1" value="<?php if ($userexists == "true" or $nouserpass == "true" or $username<>"") { print($username); } ?>" > <?php if($hidehelp == "0") { print("<img src=\"images/help.png\" onMouseover=\"document.getElementById('cspinfo').i nnerHTML = '".$infoname."';\" onMouseout=\"document.getElementById('cspinfo').in nerHTML = '';\">"); } ?><br><br> Contraseña:<br> <input type="text" name="password" size="20" tabindex="2" value="<?php if ($userexists == "true" or $nouserpass == "true" or $password<>"") { print($password); } ?>"> <?php if($hidehelp == "0") { print("<img src=\"images/help.png\" onMouseover=\"document.getElementById('cspinfo').i nnerHTML = '".$infopassword."';\" onMouseout=\"document.getElementById('cspinfo').in nerHTML = '';\">"); } ?><br><br> Nombre del Cliente:<br> <input type="text" name="displayname" size="20" tabindex="3" value="<?php if ($userexists == "true" or $nouserpass == "true" or $displayname<>"") { print($displayname); } ?>"> <?php if($hidehelp == "0") { print("<img src=\"images/help.png\" onMouseover=\"document.getElementById('cspinfo').i nnerHTML = '".$infodisplayname."';\" onMouseout=\"document.getElementById('cspinfo').in nerHTML = '';\">"); } ?><br><br> Correo:<br> <input type="text" name="email" size="20" tabindex="5" value="<?php if ($userexists == "true" or $nouserpass == "true" or $email<>"") { print($email); } ?>"> <?php if($hidehelp == "0") { print("<img src=\"images/help.png\" onMouseover=\"document.getElementById('cspinfo').i nnerHTML = '".$infoemail."';\" onMouseout=\"document.getElementById('cspinfo').in nerHTML = '';\">"); } ?><br><br> Meses: <b><font color="#FF0000"><u>1</u></font></b> Mes <br><br> <fieldset> <legend class="addedit">Servicios(s): <?php if($hidehelp == "0") { print("<img src=\"images/help.png\" onMouseover=\"document.getElementById('cspinfo').i nnerHTML = '".$infoprofiles."';\" onMouseout=\"document.getElementById('cspinfo').in nerHTML = '';\">"); } ?><br></legend> <table width="100%" valign="top" cellpadding="0" cellspacing="0"> <?php if ($usedefaults == "true" and $userexists == "false") { $lr = "0"; $conn2 = @mysql_connect($dbhost,$dbuser,$dbpass) or die ("Error connecting to database"); mysql_select_db($dbname, $conn2); $sql2 = mysql_query("SELECT * FROM cmum_profiles") or die ("Error selecting database"); $sql3 = mysql_query("SELECT * FROM cmum_settings WHERE id='1'") or die ("Error selecting database"); $numprof = mysql_num_rows($sql2); $line3=mysql_fetch_array($sql3); while($line2=mysql_fetch_array($sql2)) { if ($lr == "0") { $dbprof = unserialize($line3["def_profiles"]); if ($dbprof <> "") { $checked = ""; foreach($dbprof as $printprof) { if ($printprof == $line2["id"]) { $checked = "checked=\"checked\""; } } } else { $checked = ""; } print("<tr width=\"100%\" valign=\"top\"><td width=\"50%\" valign=\"top\"><input type=\"checkbox\" name=\"profiles[]\" tabindex=\"12\" value=\"".$line2["id"]."\" ".$checked."/>".$line2["name"]."</td>"); $lr = "1"; } else { $dbprof = unserialize($line3["def_profiles"]); if ($dbprof <> "") { $checked = ""; foreach($dbprof as $printprof) { if ($printprof == $line2["id"]) { $checked = "checked=\"checked\""; } } } else { $checked = ""; } print("<td width=\"50%\" valign=\"top\"><input type=\"checkbox\" name=\"profiles[]\" tabindex=\"12\" value=\"".$line2["id"]."\" ".$checked."/>".$line2["name"]."</td></tr>"); $lr = "0"; } } mysql_close($conn2); } if ($userexists == "true" and $usedefaults == "false") { $lr = "0"; $conn2 = @mysql_connect($dbhost,$dbuser,$dbpass) or die ("Error connecting to database"); mysql_select_db($dbname, $conn2); $sql2 = mysql_query("SELECT * FROM cmum_profiles") or die ("Error selecting database"); $numprof = mysql_num_rows($sql2); while($line2=mysql_fetch_array($sql2)) { if ($lr == "0") { $dbprof = unserialize($profiles); if ($dbprof <> "") { $checked = ""; foreach($dbprof as $printprof) { if ($printprof == $line2["id"]) { $checked = "checked=\"checked\""; } } } else { $checked = ""; } print("<tr width=\"100%\" valign=\"top\"><td width=\"50%\" valign=\"top\"><input type=\"checkbox\" name=\"profiles[]\" tabindex=\"12\" value=\"".$line2["id"]."\" ".$checked."/>".$line2["name"]."</td>"); $lr = "1"; } else { $dbprof = unserialize($profiles); if ($dbprof <> "") { $checked = ""; foreach($dbprof as $printprof) { if ($printprof == $line2["id"]) { $checked = "checked=\"checked\""; } } } else { $checked = ""; } print("<td width=\"50%\" valign=\"top\"><input type=\"checkbox\" name=\"profiles[]\" tabindex=\"12\" value=\"".$line2["id"]."\" ".$checked."/>".$line2["name"]."</td></tr>"); $lr = "0"; } } mysql_close($conn2); } if ($userexists == "true" and $usedefaults == "true") { $lr = "0"; $conn2 = @mysql_connect($dbhost,$dbuser,$dbpass) or die ("Error connecting to database"); mysql_select_db($dbname, $conn2); $sql2 = mysql_query("SELECT * FROM cmum_profiles") or die ("Error selecting database"); $numprof = mysql_num_rows($sql2); while($line2=mysql_fetch_array($sql2)) { if ($lr == "0") { $dbprof = unserialize($profiles); if ($dbprof <> "") { $checked = ""; foreach($dbprof as $printprof) { if ($printprof == $line2["id"]) { $checked = "checked=\"checked\""; } } } else { $checked = ""; } print("<tr width=\"100%\" valign=\"top\"><td width=\"50%\" valign=\"top\"><input type=\"checkbox\" name=\"profiles[]\" tabindex=\"12\" value=\"".$line2["id"]."\" ".$checked."/>".$line2["name"]."</td>"); $lr = "1"; } else { $dbprof = unserialize($profiles); if ($dbprof <> "") { $checked = ""; foreach($dbprof as $printprof) { if ($printprof == $line2["id"]) { $checked = "checked=\"checked\""; } } } else { $checked = ""; } print("<td width=\"50%\" valign=\"top\"><input type=\"checkbox\" name=\"profiles[]\" tabindex=\"12\" value=\"".$line2["id"]."\" ".$checked."/>".$line2["name"]."</td></tr>"); $lr = "0"; } } mysql_close($conn2); } if ($userexists == "false" and $usedefaults == "false") { $lr = "0"; $conn2 = @mysql_connect($dbhost,$dbuser,$dbpass) or die ("Error connecting to database"); mysql_select_db($dbname, $conn2); $sql2 = mysql_query("SELECT * FROM cmum_profiles") or die ("Error selecting database"); $numprof = mysql_num_rows($sql2); while($line2=mysql_fetch_array($sql2)) { if ($lr == "0") { print("<tr width=\"100%\" valign=\"top\"><td width=\"50%\" valign=\"top\"><input type=\"checkbox\" name=\"profiles[]\" tabindex=\"12\" value=\"".$line2["id"]."\"/>".$line2["name"]."</td>"); $lr = "1"; } else { print("<td width=\"50%\" valign=\"top\"><input type=\"checkbox\" name=\"profiles[]\" tabindex=\"12\" value=\"".$line2["id"]."\"/>".$line2["name"]."</td></tr>"); $lr = "0"; } } mysql_close($conn2); } ?> </table> <?php if ($numprof == 0) { print("No profiles added!"); } else { print("<br><input type=\"checkbox\" name=\"allprof\" onClick=\"checkedAll(adduser)\">Todos"); } ?> </fieldset> Comentario:<br> <textarea name="comment" cols="50" rows="6" tabindex="14"><?php if ($userexists == "true" or $nouserpass == "true" or $comment<>"") { print($comment); } ?></textarea> <br><br> <input type="submit" name="badduser" value="Agregar" tabindex="15" class="submit" accesskey="s" title="(ALT+S)"> <input type="submit" name="badduser" value="Limpiar" tabindex="19" class="submit" accesskey="c" title="(ALT+C)" onClick="focus();adduser.username.focus()"> </form> <?php $conn = @mysql_connect($dbhost,$dbuser,$dbpass) or die ("Error connecting to database"); mysql_select_db($dbname, $conn); $sql2 = mysql_query("SELECT * FROM cmum_dealer WHERE username='".$_SESSION["loginuser"]."'"); $cred=mysql_fetch_array($sql2); mysql_close($conn); ?>Creditos Disponibles: <b><font color="#FF0000">( <u><?php print($cred["creditos"]); ?></u> )</font> </b> </td> <td width="370" height="20" valign="top"><div id="cspinfo" style="width: 230px"></div></td> <td width="12" height="20" valign="top"> </td> |
| |||
Respuesta: tengo un formulario de usuario y password consegui esto <?php function genera_password($longitud,$tipo="alfanumerico") { if ($tipo=="alfanumerico"){ $rando="[^A-Z0-9]"; } return substr(eregi_replace($rando, "", md5(rand())), 0, $longitud); } echo "".genera_password(8).""; ?> pero me tira eror Deprecated: Function eregi_replace() is deprecated y como puedo implementarlo en el fomulariodel user y pass |
| |||
Respuesta: tengo un formulario de usuario y password Hace algunos años me encontré con esté código por internet, a mi me sirvió mucho en aquellos tiempos en los que no comprendia bien PHP. La función genera una cadena alfanumerica
Código PHP:
Ver original por medio de este llamado determinas con que caracteristicas quieres tu cadena de texto:
Código PHP:
Ver original RandomString(Tamaño de la cadena, LETRAS MAYUSCULAS, numeros, caracteres especiales) cambias el TRUE por FALSE dado el caso que quieras desactivar la opción para cada caso respectivamente. |
Etiquetas: |