antiblock
diamwall
  • Chatbox

    You don't have permission to chat.
    Load More
Sign in to follow this  
Valenza

[Duvida] Função Para Senha Ser Igual A Repetir Senha

9 posts in this topic

Boas... estou com um formulário de cadastro em php e HTML , porém meu formulário padrao contem apenas NOME,EMAIL,APAGAR PERSONAGEM, LOGIN SENHA, e estou a criar o REPETIR SENHA ,para nao ter erros na hra de criar, e para que o jogador nao precise criar mais de um email (pois no meu formulario é limitado apenas 1 cadastro por email), procurei funções em javascript de colocar isso, mas todos dao errados... o que eu poderia colocar para dar certo isso? o que escrever? obrigado

Share this post


Link to post
Share on other sites
antiblock
diamwall

em php sei, em java não mas deve ser fácil migrar para lá.

 

simplesmente usas um if, deste género:

 

 

variáveis (coloquei estas para entenderes o meu ponto)

$password

$repassword

 

 

No formulário tens estes dois campos:

 

Password(a qual será armazenada na variável $password)

Repetir password((a qual será armazenada na variável $repassword)

 

 

Eis um if para ser fácil de entenderes:

 

 

If $repassword=$password then

 

*código de registo, +mensagem de sucesso*

 

else

 

mensagem "As passwords são diferentes"

 

end if

 

 

Desta maneira não necessitas de javascript, apenas php.

 

No entanto, caso queiras formulários a mostrarem aquela cruzinha ou um certo quando ambas as passwords estão correctas, já precisares de java.

 

Como não percebi se era esta última situação que querias meti a mais fácil.

 

 

Edit: a estrutura do if está em vb, pois é a mais fácil de entender.

Caso queiras posso enviar-te a estrutura em php.

Share this post


Link to post
Share on other sites

eu nem queria esses negocios complexos de indicar a cruzinha de correto e nada.. somente a mensagem de "digitou senhas diferentes" quando a pessoa que se cadastra erra... entao acho que o php seria viavel entao, né? outra coisa... minha caixa de texto, se eu digito um email por exemplo " kasfkaskfagk " sem por o @+host+.com , ele consegue salvar... e já vi cadastros que informam "digite um email válido" , no php também se faz isso? tenho um script aqui pronto , onde preciso somente implementar estes detalhes...

 

EDIT: E aqueles negocios de "login já existe, email já existe" estes dois campos já sao suficiente...

 

Thx

Share this post


Link to post
Share on other sites

Penso que seja isto:

 

 

<html>
<head>
<script>
function validarPass(){
pass1 = document.f1.pass1.value
pass2 = document.f1.pass2.value
 
if (pass1 == pass2)
alert("PASSWORDS IGUAIS")
else
alert("PASSWORDS DIFERENTES")
}
</script>
</head>
 
<body>
 
Confirmar Password
<br>
<br>
<form action="" name="f1">
Password: <input type="password" name="pass1" size="20">
<br>
Confirmar Password: <input type="password" name="pass2" size="20">
<br>
<input type="button" value="Validar" onClick="validarPass()">
</form>
 
</body>
</html>

 
Espero ter ajudado.

Share this post


Link to post
Share on other sites

Deixo-te aqui uma pagina registo pega o que quiseres :

<div id="content">			<div class="postui2 text-title">					<h2>                    Criar Conta - M2Dragon                                        </h2>								</div>				<div class="postui2 text-con">				<div class="con-wrap"><?PHPfunction get_client_ip() {     $ipaddress = '';     if ($_SERVER['HTTP_CLIENT_IP'])         $ipaddress = $_SERVER['HTTP_CLIENT_IP'];     else if($_SERVER['HTTP_X_FORWARDED_FOR'])         $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];     else if($_SERVER['HTTP_X_FORWARDED'])         $ipaddress = $_SERVER['HTTP_X_FORWARDED'];     else if($_SERVER['HTTP_FORWARDED_FOR'])         $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];     else if($_SERVER['HTTP_FORWARDED'])         $ipaddress = $_SERVER['HTTP_FORWARDED'];     else if($_SERVER['REMOTE_ADDR'])         $ipaddress = $_SERVER['REMOTE_ADDR'];     else         $ipaddress = 'UNKNOWN';     return $ipaddress; }    $regCoins = 0; // Startcoins    $laufZeit = 365; //Tage autoloot,safebox  $calcLZ = (60*60*24)*365;  $expireStamp = time()+$calcLZ;  $expireDate = date("Y-m-d H:i:s",$expireStamp);    if($serverSettings['register_on'] && (!isset($_SESSION['user_admin']) && !checkInt($_SESSION['user_admin']) && !$_SESSION['user_admin']>=0)) {      if(isset($_POST['submit']) && $_POST['submit']=="REGISTAR") {      if((checkAnum($_POST['account']) && strlen($_POST['account'])>=8 && strlen($_POST['account'])<=16) && checkAnum($_POST['pass'])  && strlen($_POST['pass'])>=8 && strlen($_POST['pass2'])<=16 && !empty($_POST['pass2']) && (checkName($_POST['uname']) && strlen($_POST['uname'])>=3 && strlen($_POST['uname'])<=20) && $_POST['pass']==$_POST['pass2'] && checkMail($_POST['email']) && strlen($_POST['email'])<=40 && $_POST['captcha']==$_SESSION['captcha_id'] && $_POST['email']==$_POST['email2'] && (checkAnum($_POST['sicherheitsa']) && strlen($_POST['sicherheitsa'])>=3 && strlen($_POST['sicherheitsa'])<=16) && checkInt($_POST['sicherheitsf']) && (checkAnum($_POST['loeschcode']) && strlen($_POST['loeschcode'])==7)) {        $hashSF = md5($_POST['sicherheitsa']);        $sfNum = mysql_real_escape_string($_POST['sicherheitsf']);        $lcode = mysql_real_escape_string($_POST['loeschcode']);                $zuFall = rand(99999,999999999);        $userpass=mysql_real_escape_string($_POST['pass']);                $aktivHash = ($serverSettings['mail_activation']) ? md5($zuFall):'';        $accountStatus = ($serverSettings['mail_activation']) ? 'BLOCK':'OK';			$tuserip = get_client_ip();                $sqlCmd = "INSERT INTO account.account         (login,password,real_name,email,social_id,question1,answer1,create_time,status,coins,autoloot_expire,safebox_expire,web_aktiviert,web_ip,last_play)         VALUES         ('".$_POST['account']."',PASSWORD('".$userpass."'),'".mysql_real_escape_string($_POST['uname'])."','".mysql_real_escape_string($_POST['email'])."','".$lcode."','".$sfNum."','".$hashSF."','".$sqlZeit."','".$accountStatus."','".$regCoins."','".$expireDate."','".$expireDate."','".$aktivHash."','".$tuserip."',NOW())";        $sqlQry = mysql_query($sqlCmd,$sqlServ);        if($sqlQry) {                              $absender = $serverSettings['titel']." Registration";          $email = $serverSettings['reg_mail'];          $empfaenger = $_POST['email'];          $mail_body = "Hallo ".$_POST['uname'].",                    deine Registration auf ".$serverSettings['titel']." war erfolgreich! Um auch auf dem Server spielen zu können, musst du deinen Account aktivieren.          Das kannst du über den folgenden Link tun:                    ".$serverSettings['url']."/index.php?s=login&do=aktivieren&hash=".$aktivHash."                    Deine Daten sind:          Account: ".$_POST['account']."          Passwort: ".$userpass."                    Löschcode: ".$lcode."          Sicherheitsfrage: ".$sFrage[$sfNum]."          Antwort: ".$_POST['sicherheitsa']."                    Viel Spaß beim Spielen,                    Dein ".$serverSettings['titel']."-Team                              Diese E-Mail wurde automatisch generiert. Bitte keine Antworten an diese Adresse schicken.";          $titel = "Registrierung auf ".$serverSettings['titel'];                    $header = "X-Priority: 3n";          $header .= "X-Mailer: ".$serverSettings['titel']." Homepage Mailern";          $header .= "MIME-Version: 1.0n";          $header .= "From: ".$absender." <".$serverSettings['reg_mail'].">n";          $header .= "Reply-To: ".$serverSettings['reg_mail']."n";          $header .= "Content-Type: text/plain; charset=iso-8859-1n";                              if($serverSettings['mail_activation']) {            mail($empfaenger, $titel, $mail_body, $header);            echo'<p class="meldung">Conta criada com sucesso. Ative a sua conta e Divirta-se!!</p>';          }          else {            echo'<p class="meldung">Conta criada com sucesso. Divirta-se!!</p>';          }                  }        else {          echo'<p class="meldung">Não foi possivel registar: A conta já existe.</p>';        }              }      else {        echo'<p class="meldung">Não foi possivel registar: Especifique todos os campos corretamente</p>';      }    }  ?>    <p>Todos os campos são obrigatorios e devem ser preenchidos com atenção.<?PHP if($serverSettings['mail_activation']) { echo'<br/><b>Der Account wird per E-Mail aktiviert, also eine richtige E-Mail eingeben!</b>'; } ?></p>    <form action="index.php?s=registar" method="POST">      <table>        <tr>          <th class="topLine">Jogador:</th>          <td class="tdunkel"><input class="txt" type="text" name="account" maxlength="16" size="16"/>  <br> 8-16 Caráct. (de a-Z,0-9)</td>        </tr>        <tr>          <th class="topLine">Nome:</th>          <td class="thell"><input class="txt" type="text" name="uname" maxlength="16" size="16"/> <br> 3-20 Caráct. (de a-Z,0-9)</td>        </tr>        <tr>          <th class="topLine">Password:</th>          <td class="tdunkel"><input class="txt" type="password" name="pass" maxlength="16" size="16"/> <br> 8-16 Caráct. (de a-Z,0-9)</td>        </tr>        <tr>          <th class="topLine">Repita a Password:</th>          <td class="thell"><input class="txt" type="password" name="pass2" maxlength="16" size="16"/></td>        </tr>        <tr>          <th class="topLine">E-Mail:</th>          <td class="tdunkel"><input class="txt" type="text" name="email" maxlength="50" size="25"/><br> max. 40 Caráct.</td>        </tr>        <tr>          <th class="topLine">Repita o E-Mail:</th>          <td class="thell"><input class="txt" type="text" name="email2" maxlength="50" size="25"/></td>        </tr>        <tr>          <th class="topLine">Codigo de Apagar Personagem:</th>          <td class="tdunkel"><input class="txt" type="text" name="loeschcode" maxlength="7" size="7"/> <br> 7 Caráct. (de a-Z,0-9)</td>        </tr>        <tr>          <th class="topLine">Pergunta de segurança:</th>          <td class="thell">            <select name="sicherheitsf">              <?PHP                foreach($sFrage AS $fragew => $frage) {                  echo'<option value="'.$fragew.'">'.$frage.'</option>';                }              ?>            </select>            <input class="txt" type="text" name="sicherheitsa" maxlength="16" size="16"/> <br> 3-16 Carácteres (de a-Z,0-9)          </td>        </tr>        <tr>          <th class="topLine">Captcha:</th>          <td class="tdunkel"><img src="./captcha/captcha.php" title="Captcha"/>  <br> <input class="txt" type="text" name="captcha" maxlength="5" size="5"/></td>        </tr>        <tr>          <th class="topLine" style="text-align:center;" colspan="2"><input type="submit" value="REGISTAR" name="submit" class="button1">        </tr>      </table>    </form>  <?PHP  }  else {    echo'<p class="meldung">O Registo foi desativado, a abertura oficial do servidor ainda não ocorreu.</p>';  }?>				</div>  </div> 				<div class="postui2 text-end">                                                   </div></div> 

Share this post


Link to post
Share on other sites

 

Penso que seja isto:

 

 

<html>
<head>
<script>
function validarPass(){
pass1 = document.f1.pass1.value
pass2 = document.f1.pass2.value
 
if (pass1 == pass2)
alert("PASSWORDS IGUAIS")
else
alert("PASSWORDS DIFERENTES")
}
</script>
</head>
 
<body>
 
Confirmar Password
<br>
<br>
<form action="" name="f1">
Password: <input type="password" name="pass1" size="20">
<br>
Confirmar Password: <input type="password" name="pass2" size="20">
<br>
<input type="button" value="Validar" onClick="validarPass()">
</form>
 
</body>
</html>

 
Espero ter ajudado.

 

Se eu mandar por PM, me ajudarias com isso? pois eu adicionei seu codigo de exemplo e funcionou, mas no meu formulario em si nao funcionou.. ele registra mesmo digitando incorretamente... mas dei +1 pela ajuda

 

 

Deixo-te aqui uma pagina registo pega o que quiseres :

<div id="content">			<div class="postui2 text-title">					<h2>                    Criar Conta - M2Dragon                                        </h2>								</div>				<div class="postui2 text-con">				<div class="con-wrap"><?PHPfunction get_client_ip() {     $ipaddress = '';     if ($_SERVER['HTTP_CLIENT_IP'])         $ipaddress = $_SERVER['HTTP_CLIENT_IP'];     else if($_SERVER['HTTP_X_FORWARDED_FOR'])         $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];     else if($_SERVER['HTTP_X_FORWARDED'])         $ipaddress = $_SERVER['HTTP_X_FORWARDED'];     else if($_SERVER['HTTP_FORWARDED_FOR'])         $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];     else if($_SERVER['HTTP_FORWARDED'])         $ipaddress = $_SERVER['HTTP_FORWARDED'];     else if($_SERVER['REMOTE_ADDR'])         $ipaddress = $_SERVER['REMOTE_ADDR'];     else         $ipaddress = 'UNKNOWN';     return $ipaddress; }    $regCoins = 0; // Startcoins    $laufZeit = 365; //Tage autoloot,safebox  $calcLZ = (60*60*24)*365;  $expireStamp = time()+$calcLZ;  $expireDate = date("Y-m-d H:i:s",$expireStamp);    if($serverSettings['register_on'] && (!isset($_SESSION['user_admin']) && !checkInt($_SESSION['user_admin']) && !$_SESSION['user_admin']>=0)) {      if(isset($_POST['submit']) && $_POST['submit']=="REGISTAR") {      if((checkAnum($_POST['account']) && strlen($_POST['account'])>=8 && strlen($_POST['account'])<=16) && checkAnum($_POST['pass'])  && strlen($_POST['pass'])>=8 && strlen($_POST['pass2'])<=16 && !empty($_POST['pass2']) && (checkName($_POST['uname']) && strlen($_POST['uname'])>=3 && strlen($_POST['uname'])<=20) && $_POST['pass']==$_POST['pass2'] && checkMail($_POST['email']) && strlen($_POST['email'])<=40 && $_POST['captcha']==$_SESSION['captcha_id'] && $_POST['email']==$_POST['email2'] && (checkAnum($_POST['sicherheitsa']) && strlen($_POST['sicherheitsa'])>=3 && strlen($_POST['sicherheitsa'])<=16) && checkInt($_POST['sicherheitsf']) && (checkAnum($_POST['loeschcode']) && strlen($_POST['loeschcode'])==7)) {        $hashSF = md5($_POST['sicherheitsa']);        $sfNum = mysql_real_escape_string($_POST['sicherheitsf']);        $lcode = mysql_real_escape_string($_POST['loeschcode']);                $zuFall = rand(99999,999999999);        $userpass=mysql_real_escape_string($_POST['pass']);                $aktivHash = ($serverSettings['mail_activation']) ? md5($zuFall):'';        $accountStatus = ($serverSettings['mail_activation']) ? 'BLOCK':'OK';			$tuserip = get_client_ip();                $sqlCmd = "INSERT INTO account.account         (login,password,real_name,email,social_id,question1,answer1,create_time,status,coins,autoloot_expire,safebox_expire,web_aktiviert,web_ip,last_play)         VALUES         ('".$_POST['account']."',PASSWORD('".$userpass."'),'".mysql_real_escape_string($_POST['uname'])."','".mysql_real_escape_string($_POST['email'])."','".$lcode."','".$sfNum."','".$hashSF."','".$sqlZeit."','".$accountStatus."','".$regCoins."','".$expireDate."','".$expireDate."','".$aktivHash."','".$tuserip."',NOW())";        $sqlQry = mysql_query($sqlCmd,$sqlServ);        if($sqlQry) {                              $absender = $serverSettings['titel']." Registration";          $email = $serverSettings['reg_mail'];          $empfaenger = $_POST['email'];          $mail_body = "Hallo ".$_POST['uname'].",                    deine Registration auf ".$serverSettings['titel']." war erfolgreich! Um auch auf dem Server spielen zu können, musst du deinen Account aktivieren.          Das kannst du über den folgenden Link tun:                    ".$serverSettings['url']."/index.php?s=login&do=aktivieren&hash=".$aktivHash."                    Deine Daten sind:          Account: ".$_POST['account']."          Passwort: ".$userpass."                    Löschcode: ".$lcode."          Sicherheitsfrage: ".$sFrage[$sfNum]."          Antwort: ".$_POST['sicherheitsa']."                    Viel Spaß beim Spielen,                    Dein ".$serverSettings['titel']."-Team                              Diese E-Mail wurde automatisch generiert. Bitte keine Antworten an diese Adresse schicken.";          $titel = "Registrierung auf ".$serverSettings['titel'];                    $header = "X-Priority: 3n";          $header .= "X-Mailer: ".$serverSettings['titel']." Homepage Mailern";          $header .= "MIME-Version: 1.0n";          $header .= "From: ".$absender." <".$serverSettings['reg_mail'].">n";          $header .= "Reply-To: ".$serverSettings['reg_mail']."n";          $header .= "Content-Type: text/plain; charset=iso-8859-1n";                              if($serverSettings['mail_activation']) {            mail($empfaenger, $titel, $mail_body, $header);            echo'<p class="meldung">Conta criada com sucesso. Ative a sua conta e Divirta-se!!</p>';          }          else {            echo'<p class="meldung">Conta criada com sucesso. Divirta-se!!</p>';          }                  }        else {          echo'<p class="meldung">Não foi possivel registar: A conta já existe.</p>';        }              }      else {        echo'<p class="meldung">Não foi possivel registar: Especifique todos os campos corretamente</p>';      }    }  ?>    <p>Todos os campos são obrigatorios e devem ser preenchidos com atenção.<?PHP if($serverSettings['mail_activation']) { echo'<br/><b>Der Account wird per E-Mail aktiviert, also eine richtige E-Mail eingeben!</b>'; } ?></p>    <form action="index.php?s=registar" method="POST">      <table>        <tr>          <th class="topLine">Jogador:</th>          <td class="tdunkel"><input class="txt" type="text" name="account" maxlength="16" size="16"/>  <br> 8-16 Caráct. (de a-Z,0-9)</td>        </tr>        <tr>          <th class="topLine">Nome:</th>          <td class="thell"><input class="txt" type="text" name="uname" maxlength="16" size="16"/> <br> 3-20 Caráct. (de a-Z,0-9)</td>        </tr>        <tr>          <th class="topLine">Password:</th>          <td class="tdunkel"><input class="txt" type="password" name="pass" maxlength="16" size="16"/> <br> 8-16 Caráct. (de a-Z,0-9)</td>        </tr>        <tr>          <th class="topLine">Repita a Password:</th>          <td class="thell"><input class="txt" type="password" name="pass2" maxlength="16" size="16"/></td>        </tr>        <tr>          <th class="topLine">E-Mail:</th>          <td class="tdunkel"><input class="txt" type="text" name="email" maxlength="50" size="25"/><br> max. 40 Caráct.</td>        </tr>        <tr>          <th class="topLine">Repita o E-Mail:</th>          <td class="thell"><input class="txt" type="text" name="email2" maxlength="50" size="25"/></td>        </tr>        <tr>          <th class="topLine">Codigo de Apagar Personagem:</th>          <td class="tdunkel"><input class="txt" type="text" name="loeschcode" maxlength="7" size="7"/> <br> 7 Caráct. (de a-Z,0-9)</td>        </tr>        <tr>          <th class="topLine">Pergunta de segurança:</th>          <td class="thell">            <select name="sicherheitsf">              <?PHP                foreach($sFrage AS $fragew => $frage) {                  echo'<option value="'.$fragew.'">'.$frage.'</option>';                }              ?>            </select>            <input class="txt" type="text" name="sicherheitsa" maxlength="16" size="16"/> <br> 3-16 Carácteres (de a-Z,0-9)          </td>        </tr>        <tr>          <th class="topLine">Captcha:</th>          <td class="tdunkel"><img src="./captcha/captcha.php" title="Captcha"/>  <br> <input class="txt" type="text" name="captcha" maxlength="5" size="5"/></td>        </tr>        <tr>          <th class="topLine" style="text-align:center;" colspan="2"><input type="submit" value="REGISTAR" name="submit" class="button1">        </tr>      </table>    </form>  <?PHP  }  else {    echo'<p class="meldung">O Registo foi desativado, a abertura oficial do servidor ainda não ocorreu.</p>';  }?>				</div>  </div> 				<div class="postui2 text-end">                                                   </div></div> 

 

Obrigado, isso nao sei o que serve algumas coisas, pois nao sei o fundamento do site... e nao conheço muito essas linhas de comando xD mas de qq forma +1 por ajudar

Share this post


Link to post
Share on other sites

Para validar o email não é preciso meter código nenhum extenso, basta definir o tipo de input para email na form, por exemplo:

 

 

E-mail: <input type="email" name="email">

 

 

No entanto com o input type ele por vezes só verifica se te um @.

 

Vou ver onde anda aqui o código em php para verificar se tem @ + . e já te digo.

Share this post


Link to post
Share on other sites

carpinteiro , vou mandar algo por PM, ok? dei +1 por isso, realmente ajudou :3

Share this post


Link to post
Share on other sites

Está bem :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this