View Single Post
Old 22.12.2006, 08:36   #1
AHTUKULLEP
Архивный участник
 
Join Date: Feb 2006
Posts: 57
Default Помогите - Код безопасности

Вобшем всё пашет:

1) Копируешь code.php в папку pages
2) login.php должен выглядеть так:
Code:
<?
require 'config.php';
require 'pages/functions.php';
require 'pages/query.php';

session_start();
if($_SESSION['sec_code_session'] != $_POST['code'] or empty($_POST['code']))
{
header("Content-type: text/html; charset=windows-1251");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-relative");

echo <<< END
<?xml version="1.0" encoding="windows-1251"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251" />
<title>Error</title>
</head>
<body>
Ошибка: проверочный код введен неверно...
<a href="java script:history.back(1)">Назад</a><br />
</body>
</html>
END;
die();
}

if ($_POST['action']=='login') 
 {
  connectdb($CONFIG['dbdbname'], $CONFIG['dbaddress'], $CONFIG['dbuser'], $CONFIG['dbpass']);
  $postusername = isset($_POST['username'])?$_POST['username']:null;
  $postpassword = isset($_POST['password'])?$_POST['password']:null;
  $postusername = antiinjection($postusername);
  $postpassword = antiinjection($postpassword);
  $result = mssql_query(sprintf(SELECT_USER_PASS,$postusername));
  $rows=mssql_num_rows($result);
  if ($rows>0) 
   {
	$rows=mssql_fetch_assoc($result); 
	extract($rows);
	$password = '0x'.bin2hex($password);
	if (@encrypt($postpassword)==$password) 
	 {
	  @setcookie("login", $account, time()+2592000);
	  @setcookie("pass", md5($password), time()+2592000);
	  quickrefresh('index.php');
	 } 
	else 
	 {
	  echo '<script> alert("Неверный пароль."); </script>';
	 }
   } 
  else 
   {
	echo '<script> alert("Неправильный логин."); </script>';
   }
  quickrefresh('index.php');
 } 
else 
 {
  quickrefresh('index.php');
 }

?>
3) Бери эту форму:
Code:
   <form name="login" method="post" action="login.php" onSubmit="return checkform()">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	 <tr>
	  <td class="ac">
	   Логин<br>
	   <input name="username" type="text">
	   Пароль<br>
	   <input name="password" type="password">
	   Код подтверждения<br>
	   <img src="pages/code.php">
	   <input name="code" type="text">
	   <input type="hidden" name="action" value="login">
	   <input type="submit" name="submit" value="Войти">
	  </td>
	 </tr>
	</form>
Всё, у меня всё пашет, только теперь вы мне помогите, как цепонуть этуже хрень вот сюда:

Code:
<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
<script>
function isAlphaNumeric(value) 
 {
  if (value.match(/^[a-zA-Z0-9]+$/)) 
   {
	return true;
   } 
  else 
   {
	return false;
   }		
 }

function checkform() 
 {
  if(changepassword.oldpassword.value=="") 
   { 
	alert("Введите ваш старый пароль.") 
	return false; 
   }
  if(changepassword.newpassword.value=="") 
   { 
	alert("Введите ваш новый пароль.") 
	return false; 
   }
  if (!isAlphaNumeric(changepassword.newpassword.value)) 
   {
	alert("Пароль должен состоять из букв и цифр!");
	return false;
   }
  if(changepassword.newpassword2.value=="") 
   { 
	alert("Введите еще раз ваш новый пароль.") 
	return false; 
   }
  if(changepassword.oldpassword.value==changepassword.newpassword.value) 
   { 
	alert("Старый и новый пароли не должны быть одинаковыми.") 
	return false; 
   }
  return true;
 }
</script>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
 <tr>
  <td class="h-cell b-tblr t-bold">Смена пароля</td>
 </tr>
 <?=$sep?>
</table>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
 <tr>
  <td class="n-cell b-tblr p-2">
<?
securitycheck(!$logged);
$error = 0;

if($_POST['action']=='changepassword') 
 {
  $error = 2;
  connectdb($CONFIG['dbdbname'], $CONFIG['dbaddress'], $CONFIG['dbuser'], $CONFIG['dbpass']);
  $account = $_POST['login_cd'];
  $oldpassword = $_POST['oldpassword'];
  $newpassword = $_POST['newpassword'];
  $newpassword2 = $_POST['newpassword2'];
  $oldpassword = antiinjection($oldpassword);
  $newpassword = antiinjection($newpassword);
  $newpassword2 = antiinjection($newpassword2);
  $result = mssql_query (sprintf(SELECT_USER_PASS, $account));
  $rows=mssql_fetch_assoc($result); 
  extract($rows);
  $password = '0x' . bin2hex($password);
  $oldpassword = encrypt($oldpassword);
  if ($password!=$oldpassword) 
   {
	echo "Старый пароль неверен<br>";
	$error = 1;
   }
  if ((strlen($newpassword)<4 ||strlen($newpassword)>16) && $newpassword!="")
   {
	echo "Длина пароля должна быть от 4 до 16 символов.<br>";
	$error = 1;
   }
  if ($newpassword!=$newpassword2) 
   {
	echo "Retyped password is incorrect.<br>";
	$error = 1;
   }
 }
if($error<2) { ?>
<form name="changepassword" action="index.php?act=change_password" method="post" onsubmit="return checkform()" autocomplete="off">
 <table cellspacing=0 border=0 cellpadding=0 align=center>
  <tr>
   <td colspan="2" class="ac">Введите логин, старый и новый пароли </td>
  </tr>
  <tr>
   <td colspan="2"> </td>
  </tr>
  <tr>
   <td>Логин:</td>
   <td><input type=text maxlength=16 name=login_cd></td>
  </tr>
  <tr>
   <td>Старый пароль:</td>
   <td><input type=password maxlength=16 name=oldpassword></td>
  </tr>
  <tr>
   <td>Новый пароль:</td>
   <td><input type=password maxlength=16 name=newpassword></td>
  </tr>
  <tr>
   <td>Повторите новый пароль: </td>
   <td><input type=password maxlength=16 name=newpassword2></td>
  </tr>
  <tr>
   <td><input type=hidden name=action value="changepassword"></td>
   <td><input type=submit name=submit value="Послать"></td>
  </tr>
 </form>		
</table>

<?
 }
if($error==2) 
 {
  $curdate= date("F j, Y, H:i");
  if (is_writeable($logfile_cp))
   {
	$fh = fopen($logfile_cp, "a+");
	$success = fwrite($fh, "Сменен пароль у аккаунта ".$account." на ".$newpassword." ".$curdate."\r\n");
	fclose($fh);
   }
  $ip=getenv("REMOTE_ADDR");
  mssql_connect($mssql_server,$mssql_user,$mssql_pass);
  connectdb($CONFIG['dbdbname'], $CONFIG['dbaddress'], $CONFIG['dbuser'], $CONFIG['dbpass']);
  $newpassword = encrypt($newpassword);
  mssql_query(sprintf(UPDATE_PASSWORD, $newpassword, $account));
  echo 'Пароль успешно изменен.<br><br>
		Вы будете перенаправлены на главную страницу в течение 3 секунд,<br>
		если не хотите ждать, то нажмите <a href="index.php">здесь</a>.';
		delayedrefresh('index.php');
 }
?>
  </td>
 </tr>
</table>
Помогите пожалуста!!!
AHTUKULLEP is offline