|
发表于 2004-8-31 20:16:03
|
显示全部楼层
- <?php
- session_start();
- if( $current_uid == "" ) {
- echo "Please login";
- return;
- }
- $account = $current_uid;
- $oldpasswd = $_POST['oldpasswd'];
- $newpasswd1 = $_POST['newpasswd1'];
- $newpasswd2 = $_POST['newpasswd2'];
- $fp=fopen("/opt/passwd", "r+");
- if ( $fp == FALSE ) {
- echo "Open file is error! <br>";
- break;
- }
- while(!feof($fp))
- {
- $i=ftell($fp);
- $line_buf = fgets($fp,1024);
- if ( strlen($line_buf) == 0 ) return;
- $arr = explode(" ", $line_buf);
- $user = $arr[0];
- $encryptpass = $arr[1];
- $line_len = strlen($line_buf);
- $passwd_len = strlen($encryptpass);
- if( $user == $account )
- {
- $i=$i+$line_len-$passwd_len;
- if( trim(crypt($oldpasswd,$encryptpass)," \r\n") == trim($encryptpass," \r\n") )
- {
- $newencryptpass = crypt($newpasswd1);
- rewind($fp);
- fseek($fp,$i,SEEK_SET);
- fwrite($fp,$newencryptpass);
- echo "修改成功!";
- break;
- } else {
- echo "帐号或密码错误!";
- break;
- }
- }
- }
- fclose($fp);
- echo "<br>";
- echo '<center><a href="http://XXX/main.html">返回</center>';
- ?>
复制代码
/opt/passwd的格式是:帐号 密文
我以前写过的一个基于文本认证修改密码的PHP,里面也用到了你说的加密函数,不知道对你有没有帮助。 |
|