Jump to content

Verificar Password enquanto efetua o registo


Recommended Posts

Posted

Boas,

Estou no 12º Ano e estou a desenvolver o meu projeto (PAP).

Estou a trabalhar no dreaweaver e de momento não estou a conseguir verificar a password pois tenho um campo de confirmação da password e não estou a conseguir verificá-la gostaria que me dessem umas luzes pois sou amador no que toca a php e dreamweaver.

Desde já um Obrigado

Posted
<?php
header('Content-Type: text/html; charset=iso-8859-1');
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
 if (PHP_VERSION < 6) {
   $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 }
 $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
 switch ($theType) {
   case "text":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;   
   case "long":
   case "int":
     $theValue = ($theValue != "") ? intval($theValue) : "NULL";
     break;
   case "double":
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
     break;
   case "date":
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
     break;
   case "defined":
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
     break;
 }
 return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
 $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "registo")) {
 $insertSQL = sprintf("INSERT INTO cliente (`User`, Password, Nome, Apelido, Email, Morada, CodigoPostal, Localidade, N_Contribuinte, Telefone, CC) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                      GetSQLValueString($_POST['User'], "text"),
                      GetSQLValueString($_POST['Password'], "text"),
                      GetSQLValueString($_POST['Nome'], "text"),
                      GetSQLValueString($_POST['Apelido'], "text"),
                      GetSQLValueString($_POST['Email'], "text"),
                      GetSQLValueString($_POST['Morada'], "text"),
                      GetSQLValueString($_POST['CodigoPostal'], "text"),
                      GetSQLValueString($_POST['Localidade'], "text"),
                      GetSQLValueString($_POST['N_Contribuinte'], "text"),
                      GetSQLValueString($_POST['Telefone'], "text"),
                      GetSQLValueString($_POST['CC'], "text"));
/*if( $_POST['Password'] !== $_POST['Password2'] )
{
 die('Ocorreu um erro ao registar: a password e a sua confirmação devem ser iguais');
}*/
//else
//{
if( $_POST['Email'] !== $_POST['Email2'] )
{
  die('rgrtgtrhthryhhyyhhhy');
}
//}
 mysql_select_db($database_DB, $DB);
 $Result1 = mysql_query($insertSQL, $DB) or die(mysql_error());
}

Depois da password tambem é para verificar se o email tambem coincide mas gostava de fazer enquanto se efetua o registo ou seja em tempo real.

Posted

Precisas de jQuery para isso.

É uma solução (que eu utilizava)... mas a partir deste código também deveria chegar lá. Isso não é um problema de parêntesis?

Tenta mudar por isto...

if( $_POST['Password'] !== $_POST['Password2'] )
{
die('Ocorreu um erro ao registar: a password e a sua confirmação devem ser iguais');
}
else
{
 if( $_POST['Email'] !== $_POST['Email2'] )
 {
 die('Email errado!');
 }
 else{
		 //password e email correto
	 mysql_select_db($database_DB, $DB);
	 $Result1 = mysql_query($insertSQL, $DB) or die(mysql_error());
 }
} //fim de else

Posted

Boas, obrigado por todas as respostas consegui o pretendido.

Agora tenho mais um problema.

É a primeira vez que trabalho com o dreamweaver e jurei para nunca mais vou só acabar a minha PAP aqui pois ainda não percebo muito de PHP mas o que percebo o Dreamweaver parece não me ajudar na minha aprendizagem.

Ora bem o problema é que o dreamweaver não me vai buscar a variável à base de dados:

Faço o seguinte Select:

$query_Recordset1 = sprintf("SELECT Password FROM cliente WHERE Email = %s", GetSQLValueString($colname_Recordset1, "text"));

e se fizer um teste o resultado é o da declaração da variável: $colname_Recordset1 = "-1";

o problema acho que está na parte do: GetSQLValueString($colname_Recordset1, "text")

pois já na pagina de login ele não me aceitava o Username e dava-me o erro: unknown 'Napster' Column in table 'cliente'

e dado esse erro exprimentei fazer:

$LoginRS__query=sprintf("SELECT User, Password FROM cliente WHERE User='".$loginUsername."' AND Password='".$password."'");

e aceitou agora neste recordset ele não me aceita o select.

Tenho o seguinte código:

<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_Recordset1 = "-1";
if (isset($_POST['Email'])) {
$colname_Recordset1 = $_POST['Email'];
}
mysql_select_db($database_DB, $DB);
$query_Recordset1 = sprintf("SELECT Password FROM cliente WHERE Email = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $DB) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
if($totalRows_Recordset1==0)
{
$erro="Não existe nenhum utilizador com o endereço de e-mail: ".$colname_Recordset1;
}
else
{
mysql_free_result($colname_Recordset1);
}
?>

Gostava mesmo que me ajudassem pois de momento o prazo para acabar isto está a ficar curto e não me é possivel dedicar à linguagem PHP a 100% pois o horário é preenchido durante a semana e entretanto no dia 24 de março começo o estágio e não tenho tempo nem para Jogar CS:GO xD.

Obrigado.

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
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. 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.