php用户注册对密码进行MD5加密

一 代码

conn.php
<?php
	$conn = mysql_connect("localhost","root","root") or die("数据库错误".mysql_error());
	mysql_select_db("db_database21",$conn) or die("数据库错误".mysql_error());
	mysql_query("set names gb2312");
?>
 
index.php
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>使用md5对用户注册密码进行加密</title>
<style type="text/css">
<!--
body,td,th {
	font-size: 12px;
}
body {
	margin-left: 10px;
	margin-top: 10px;
	margin-right: 10px;
	margin-bottom: 10px;
}
.STYLE1 {
	font-size: 14px;
	font-weight: bold;
}
-->
</style>
</head>
<body>
<table width="777" height="587" border="0" align="center" cellpadding="0" cellspacing="0" background="images/bg.jpg">
  <tr>
    <td width="149" height="200">&nbsp;</td>
    <td width="448">&nbsp;</td>
    <td width="158">&nbsp;</td>
  </tr>
  <tr>
    <td height="187">&nbsp;</td>
    <td align="center" valign="middle">  <form id="form1" name="form1" method="post" action="index_ok.php">
    <table height="160" border="0" cellpadding="0" cellspacing="0">
      <tr>
			<td width="83" height="30" align="right" valign="middle" scope="col"><span class="STYLE1">用户名:</span></td>
        <td width="267" height="30" align="left" valign="middle" scope="col"><label for="textfield"></label>
        <input name="username" type="text" id="username" size="24" /></td>
        <td width="25" align="center" valign="middle" scope="col">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right" valign="middle" class="STYLE1" scope="col">密码:</td>
        <td height="30" align="left" valign="middle" scope="col"><input name="password" type="password" id="password" size="25" /></td>
        <td align="center" valign="middle" scope="col">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right" valign="middle" class="STYLE1" scope="col">地址:</td>
        <td height="30" align="left" valign="middle" scope="col"><input name="address" type="text" id="address" size="35" /></td>
        <td align="center" valign="middle" scope="col">&nbsp;</td>
      </tr>
      <tr>
        <td height="30" align="right" valign="middle" class="STYLE1" scope="col">电话:</td>
        <td height="30" align="left" valign="middle" scope="col"><input name="tel" type="text" id="tel" size="20" /></td>
        <td align="center" valign="middle" scope="col">&nbsp;</td>
      </tr>
      <tr>
        <td height="40" colspan="3" align="center" valign="middle" scope="col"><input type="image" name="imageField" src="images/bg2.JPG" />          
          &nbsp;&nbsp;<input type="image" name="imageField2" src="images/bg1.JPG" οnclick="form.reset();return false;" /></td>
        </tr>
    </table>
  </form>
  </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td height="200">&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
</body>
</html>
 
index_ok.php
<?php 
	include("conn/conn.php");
	if(trim($_POST[username])!= "" and trim($_POST[password])!= "" and trim($_POST[tel])!=""){
		$pwd = md5($_POST[password]);
		$sql = "insert into tb_user(username,password,address,explains)values('".$_POST[username]."','".$pwd."','".$_POST[address]."','".$_POST[tel]."')";
		$result = mysql_query($sql,$conn);
		if($result){
			echo "<font color='red'>注册成功。</font>";
		}else{
			echo "<font color='green'>注册失败!</font>";
		}
	}else{
		echo "请认真填写用户名和密码!";
	}
?>
 
二 运行结果
注册成功。
数据库数据如下:

 
  • 大小: 2.5 KB
  • 2
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你想在Flarum中使用MD5加密方式进行用户密码加密,可以按照以下步骤进行操作: 1. 修改配置文件 在Flarum的根目录下找到config.php文件,添加以下内容: ```php return [ // ... 'hashers' => [ // ... 'myhasher' => [ 'algo' => 'md5', 'prefix' => '', // 如果需要添加前缀,可以在这里设置 'suffix' => '', // 如果需要添加后缀,可以在这里设置 ], ], ]; ``` 2. 创建自定义加密方式 在Flarum的扩展目录下创建一个新文件夹,比如叫做myhasher,然后在该文件夹下创建一个新的类MyHasher.php,类的代码如下: ```php namespace MyHasher; use Illuminate\Contracts\Hashing\Hasher as HasherContract; class MyHasher implements HasherContract { public function make($value, array $options = []) { $prefix = $options['prefix'] ?? ''; $suffix = $options['suffix'] ?? ''; return md5($prefix . $value . $suffix); } public function check($value, $hashedValue, array $options = []) { $prefix = $options['prefix'] ?? ''; $suffix = $options['suffix'] ?? ''; return md5($prefix . $value . $suffix) === $hashedValue; } public function needsRehash($hashedValue, array $options = []) { return false; // 如果需要重新hash,返回true } } ``` 其中,make()方法用于加密密码,check()方法用于验证密码是否正确,needsRehash()方法用于判断是否需要重新hash。 3. 注册自定义加密方式 在Flarum的扩展目录下的extend.php文件中添加以下代码: ```php use Illuminate\Events\Dispatcher; use MyHasher\MyHasher; return function (Dispatcher $events) { $events->listen('Illuminate\Auth\Events\Attempting', function ($event) { $event->credentials['password'] = app(MyHasher::class)->make($event->credentials['password'], [ 'prefix' => 'your_prefix', // 自定义的前缀 'suffix' => 'your_suffix', // 自定义的后缀 ]); }); $events->listen('Illuminate\Auth\Events\PasswordReset', function ($event) { // 更多的事件监听可以在这里添加 }); }; $app->singleton(MyHasher::class, function () { return new MyHasher(); }); $app->register(MyHasher\MyHasherProvider::class); ``` 注册完成后,可以在Flarum的管理后台中进行测试。需要注意的是,MD5加密方式并不安全,建议使用更加安全的加密方式。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值