php實現使用者註冊密碼的crypt加密的方法

來源:互聯網
上載者:User
這篇文章主要為大家詳細介紹了php實現使用者註冊密碼的crypt加密,具有一定的參考價值,感興趣的小夥伴們可以參考一下

一、代碼

1、conn.php

<?php   $conn = mysql_connect("localhost", "root", "111") or die("串連資料庫伺服器失敗!".mysql_error()); //串連MySQL伺服器   mysql_select_db("db_database21",$conn);     //選擇資料庫db_database21   mysql_query("set names utf8");           //設定資料庫編碼格式utf8 ?>

2、index.php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>使用者註冊</title> <style type="text/css"> <!-- body,td,th {   font-size: 12px; } --> </style></head> <body> <form id="form1" name="form1" method="post" action="index_ok.php">  <fieldset style="width:500px"><legend style="font-size:16px">使用者註冊</legend><table width="300" border="0" align="center">   <tr>    <td width="77" align="right">使用者名稱:</td>    <td width="213"><input name="user" type="text" id="user" size="24" /></td>   </tr>   <tr>    <td align="right">密碼:</td>    <td><input name="pwd" type="password" id="pwd" size="25" /></td>   </tr>   <tr>    <td> </td>    <td><input type="submit" name="sub" value="註冊" />      <input type="reset" name="res" value="重設" /></td>   </tr>  </table></fieldset> </form> </body> </html>

3、index_ok.php

<?php   header("content-type:text/html;charset=utf-8"); //載入頭資訊   include("conn/conn.php");//包含資料庫連接檔案   if(trim($_POST['user'])!= "" and trim($_POST['pwd'])!= ""){//判斷輸入是否為空白     $pwd = crypt($_POST['pwd'],"key");//對輸入的密碼進行crypt加密     $sql = "insert into tb_user(username,password)values('".$_POST[user]."','". $pwd."')";//定義sql語句     $result = mysql_query($sql,$conn);//執行sql語句     if($result){       echo "<font color='red'>註冊成功。</font>";//如果結果為真提示註冊成功     }else{       echo "<font color='green'>註冊失敗!</font>";//否則提示註冊失敗     }   }else{     echo "請認真填寫使用者名稱和密碼!";//提示輸入使用者名稱和密碼   } ?>

二、運行結果

註冊成功後,資料庫顯示如下:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.