Changeset 63 for hadoop-register/forget_password.php
- Timestamp:
- Apr 24, 2009, 3:23:32 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
hadoop-register/forget_password.php
r58 r63 1 1 <? 2 3 4 5 2 /* 3 * 由使用者輸入帳號及註冊信箱,程式將判斷是否符合,再決定是否產生新密碼,送至使用者原註冊信箱。 4 * 接收由 forget_password.php 傳來的 $_GET["user"] 資料,產生新密碼後送回使用者的信箱。 5 */ 6 6 7 8 7 require_once ("./etc/init.php"); 8 include_once ("./etc/funs.php"); 9 9 10 // 第一次要求使用者輸入帳號及註冊信箱 11 if ($_POST["user"]=="" || $_POST["email"]=="") 12 { 13 echo ' 14 <SCRIPT LANGUAGE="javascript"> 15 function check_data() 10 // 第一次要求使用者輸入帳號及註冊信箱 11 if ($_POST["user"]=="" || $_POST["email"]=="") 12 { 13 echo ' 14 <HTML> 15 <HEAD> 16 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=utf-8"> 17 <TITLE> Hadoop 帳號 </TITLE> 18 <SCRIPT LANGUAGE="javascript"> 19 function check_data() 20 { 21 if (document.myForm.user.value.length == 0) 16 22 { 17 if (document.myForm.user.value.length == 0) 18 { 19 alert("帳號不可空白"); 20 return false; 21 } 22 if (document.myForm.email.value.length == 0) 23 { 24 alert("E-mail不可空白"); 25 return false; 26 } 23 alert("帳號不可空白"); 24 return false; 25 } 26 27 var mailString = document.myForm.email.value; 28 var pattern=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; 29 if (!pattern.exec(mailString) ) 30 { 31 alert(mailString + " : E-mail 格式錯誤"); 32 return false; 33 } 27 34 myForm.submit(); 28 } 29 </SCRIPT> 35 } 36 </SCRIPT> 37 <FORM ACTION="forget_password.php" METHOD="post" NAME="myForm"> 38 <TABLE WIDTH="40%" ALIGN="center"> 39 <TR> 40 <TD ALIGN="center"> 41 <FONT COLOR="#3333FF">帳號:</FONT> 42 <INPUT NAME="user" TYPE="text" SIZE="15"> 43 </TD> 44 </TR> 45 <TR> 46 <TD ALIGN="center"> 47 <FONT COLOR="#3333FF">註冊信箱:</FONT> 48 <INPUT NAME="email" TYPE="text" SIZE="15"> 49 </TD> 50 </TR> 51 <TR> 52 <TD ALIGN="center"> 53 <INPUT TYPE="button" VALUE="送出" onClick="check_data()"> 54 <INPUT TYPE="reset" VALUE="重填"> 55 </TD> 56 </TR> 57 </TABLE> 58 </FORM> 59 </HTML> 60 '; 61 } 30 62 31 <FORM ACTION="forget_password.php" METHOD="post" NAME="myForm"> 32 <TABLE WIDTH="40%" ALIGN="center"> 33 <TR> 34 <TD ALIGN="center"> 35 <FONT COLOR="#3333FF">帳號:</FONT> 36 <INPUT NAME="user" TYPE="text" SIZE="15"> 37 </TD> 38 </TR> 39 <TR> 40 <TD ALIGN="center"> 41 <FONT COLOR="#3333FF">註冊信箱:</FONT> 42 <INPUT NAME="email" TYPE="text" SIZE="15"> 43 </TD> 44 </TR> 45 <TR> 46 <TD ALIGN="center"> 47 <INPUT TYPE="button" VALUE="送出" onClick="check_data()"> 48 <INPUT TYPE="reset" VALUE="重填"> 49 </TD> 50 </TR> 51 </TABLE> 52 </FORM> 53 '; 54 } 63 // 當使用者輸入完帳號及註冊信箱後 64 else 65 { 66 $my_user = new W_user(); 67 $my_user->user = $_POST["user"]; 68 $my_user->email = $_POST["email"]; 55 69 56 // 當使用者輸入完帳號及註冊信箱後 57 else 58 { 59 $my_user = new W_user(); 60 $my_user->user = $_POST["user"]; 61 $my_user->email = $_POST["email"]; 62 $my_user->new_password = $my_user->get_new_password(); // 取得新密碼 70 // 連結資料庫 71 $link = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error()); 72 mysql_select_db($mysql_database, $link) or die(mysql_error() ); 73 mysql_query("SET NAMES 'utf8'"); 74 75 // 判斷此帳號密碼是否存在 76 $str = sprintf("SELECT `id` FROM `%s` WHERE `name` LIKE '%s' and `email` LIKE '%s' limit 1", $mysql_table, $my_user->user, $my_user->email); 77 $result = mysql_query($str , $link) or die(mysql_error() ); 78 if (mysql_num_rows($result) == 1) 79 { 63 80 64 // 連結資料庫 65 $link = mysql_connect($mysql_host, $mysql_user, $mysql_password) or die(mysql_error()); 66 mysql_select_db($mysql_database, $link) or die(mysql_error());67 mysql_query("SET NAMES 'utf8'");68 69 // 更新使用者認證碼70 $str = sprintf("UPDATE `%s` SET `password` = '%s' WHERE `user` LIKE '%s' ", $mysql_table, md5($my_user->new_password), $my_user->user);71 mysql_query($str , $link) or die(mysql_error() );72 mysql_close($link);73 74 // 寄送新密碼 75 $my_user->operator = "new_password"; // user 需要更新密碼 76 include ("smtp_mail.php"); 77 $my_user->redirect_to("http://$w_localhost", "新密碼寄送完畢");78 79 81 // 更新使用者密碼 82 $my_user->new_password = $my_user->get_new_password(); // 取得新密碼 83 $str = sprintf("UPDATE `%s` SET `password` = '%s' WHERE `user` LIKE '%s' ", $mysql_table, md5($my_user->new_password), $my_user->user); 84 mysql_query($str , $link) or die(mysql_error() ); 85 mysql_close($link); 86 87 // 寄送新密碼 88 $my_user->operator = "new_password"; // user 需要更新密碼 89 include ("smtp_mail.php"); 90 $my_user->redirect_to("http://$w_localhost", "新密碼寄送完畢"); 91 } 92 else 93 { 94 $my_user->redirect_to("http://$w_localhost", "帳號與密碼不符合"); 95 } 96 } 80 97 ?> 81 98
Note: See TracChangeset
for help on using the changeset viewer.