1
I have a loop that you should enter a random password for each record, and when you finish the loop (have created different password for each record), list the results by viewing the password.
 <?php
ob_start();
session_start();
//conexão com banco
include ("conn.php");
//definição de variáveis
$tabela = "chatoperator";
$campos = "operatorid, vclogin, dtmlastvisited, istatus, vcpassword"; 
$quant = 10; //número de ações que será realizada de cada vez 
$sec = 10; //tempo entre o envio de um pacote e outro (em segundos) 
$ok = 0;
$inicio = 0;
$fim = $inicio + $quant; 
$acentos = "<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />";
//verifica se a senha confere com a da sessão
echo $acentos;
$sql = "select $campos from $tabela where istatus = 0 limit $inicio,$fim" or die (mysql_error($sql)); 
$query = mysql_query($sql,$conexao); 
$registros = mysql_num_rows($query); 
if($registros==0){
    mysql_query("update $tabela set istatus = 0" or die (mysql_error($conexao))); 
        echo("<font face=’tahoma’>todas as senhas foram alteradas!</font>"); 
    $ok = 1;
}else{
    while($result = mysql_fetch_array($query)) {
        $operatorid = $result[0]; //operatorid
        $vclogin = $result[1]; //vclogin
        $dtmlastvisited = $result[2]; //dtmlastvisited
        $istatus = $result[3]; //istatus
        $vcpassword = $result[4]; //vcpassword
        //gera senha aleatória
        function geraSenha(){
        //caracteres que serão usados na senha randomica
            $chars = 'abcdxyswzABCDZYWSZ0123456789';
            //ve o tamnha maximo que a senha pode ter
            $max = strlen($chars) - 1;
        //declara $senha
            $senha = null;
        //loop que gerará a senha de 8 caracteres
            for($i=0;$i < 8; $i++){
            $senha .= $chars{mt_rand(0,$max)};
    }
    return $senha;          
}
$senha_randomica   =  geraSenha();
$senha = md5($senha_randomica);
mysql_query("update $tabela set istatus = 1 AND vcpassword = '$senha_randomica' where    operatorid = $operatorid") or die (mysql_error($conexao));
    echo("
<table width='100%' border='1'>
    <tr>
        <th>Identificador do Usuário</th>
        <th>Login do Usuário</th>
        <th>Data do Último Acesso</th>
        <th>Status do Acesso</th>
        <th>Senha do Usuário</th>
   </tr>
   <tr>
        <td> $operatorid </td>
        <td> $vclogin </td>
        <td> $dtmlastvisited </td>
        <td> $istatus </td>
        <td> $senha_randomica </td>
  </tr>
 </table>");
      }
   }
    mysql_free_result($query); 
    mysql_close($conexao);
    if(!$ok){
        echo("<meta http-equiv=\"refresh\" content=\"" . $sec . "\">"); 
}
?>
What is your difficulty?
– Maniero
The script is generating the SAME password for all records, the idea is that a different password would be generated for each record. Thanks for the feedback @bigown
– Eduardo Correia
Without indentation it’s hard to understand what’s going on. If you~e [Edit] the question with better formatting of the code, who knows even you find some error.
– Maniero