新聞中心
在當(dāng)今互聯(lián)網(wǎng)時代,網(wǎng)站與我們的生活息息相關(guān),大部分網(wǎng)站為了有更好的用戶體驗(yàn)或者用戶管理,都會提供登錄功能。而這個功能的重要性就在于,可以讓網(wǎng)站管理員或者會員進(jìn)行身份認(rèn)證和授權(quán),從而維護(hù)網(wǎng)站的信息安全。

創(chuàng)新互聯(lián)擁有網(wǎng)站維護(hù)技術(shù)和項目管理團(tuán)隊,建立的售前、實(shí)施和售后服務(wù)體系,為客戶提供定制化的成都網(wǎng)站建設(shè)、網(wǎng)站設(shè)計、網(wǎng)站維護(hù)、成都二樞服務(wù)器租用托管解決方案。為客戶網(wǎng)站安全和日常運(yùn)維提供整體管家式外包優(yōu)質(zhì)服務(wù)。我們的網(wǎng)站維護(hù)服務(wù)覆蓋集團(tuán)企業(yè)、上市公司、外企網(wǎng)站、商城網(wǎng)站制作、政府網(wǎng)站等各類型客戶群體,為全球千余家企業(yè)提供全方位網(wǎng)站維護(hù)、服務(wù)器維護(hù)解決方案。
但是,也不能忽視掉登錄功能也存在安全風(fēng)險,比如,網(wǎng)站密碼泄露、暴力破解、口令撞庫等問題。為了保障登錄的安全性,建立登錄時要求填寫驗(yàn)證碼、短信驗(yàn)證等手段進(jìn)行多種驗(yàn)證。
下面,我們就來介紹如何使用數(shù)據(jù)庫來實(shí)現(xiàn)網(wǎng)站登錄頁面的安全驗(yàn)證。
1.建立用戶表格
需要建立一個用戶表格來存儲用戶的信息,用戶表格一般包括ID、用戶名、密碼、郵箱、號碼等字段。
其中,密碼這個字段一定要進(jìn)行加密處理,在寫查詢語句時,可以使用加密算法對用戶輸入的密碼進(jìn)行加密后進(jìn)行數(shù)據(jù)庫查詢,這樣即使數(shù)據(jù)庫主人被黑客攻擊,也能保證數(shù)據(jù)庫信息的安全性。
2. 實(shí)現(xiàn)驗(yàn)證碼
在驗(yàn)證用戶信息的過程中,驗(yàn)證碼是最常見的一種方式,最基本的驗(yàn)證碼是顯示在頁面上的圖形驗(yàn)證碼。對于圖形驗(yàn)證碼的產(chǎn)生,可以使用PHP CAPTCHA類庫,具體的可以看下面的代碼示例。
session_start();
//隨機(jī)生成一組4位數(shù)字驗(yàn)證碼
$randCode = rand(1000, 9999);
//將生成的驗(yàn)證碼存放在SESSION中,方便后續(xù)進(jìn)行比對
$_SESSION[‘code’] = $randCode;
//創(chuàng)建圖像,前面的參數(shù)為畫布的寬度,后面的參數(shù)為畫布的高度
$img = imagecreate(60, 25);
//設(shè)置畫布的背景顏色
$bgColor = imagecolorallocate($img, 146, 204, 229);
//設(shè)置字體顏色
$fontColor = imagecolorallocate($img, 0, 0, 0);
//將生成的數(shù)字中的每個數(shù)字單獨(dú)處理
for($i=0;$i
$randChar = $randCode{$i};
//在圖像中寫入數(shù)字
imagestring($img, 5, 10+($i*15), 5, utf8_decode($randChar), $fontColor);
}
//設(shè)置內(nèi)容類型
header(“Content-type:image/png”);
//將圖像以PNG格式輸出到頁面
imagepng($img);
//銷毀所創(chuàng)建的圖像
imagedestroy($img);
?>
3. 實(shí)現(xiàn)短信驗(yàn)證
除了圖形驗(yàn)證碼,現(xiàn)在也有越來越多的平臺支持短信驗(yàn)證。在實(shí)現(xiàn)短信驗(yàn)證時,需要建立一個短信接口,調(diào)用該接口發(fā)送短信驗(yàn)證碼,然后再通過用戶輸入的驗(yàn)證碼與服務(wù)器發(fā)送的短信驗(yàn)證碼進(jìn)行匹配。
接口的實(shí)現(xiàn)可以使用阿里大于短信接口,如下代碼示例所示:
session_start();
//向S接口發(fā)送請求
$url = “https://sapi.aliyun.com:443/api/push”;
//構(gòu)造請求參數(shù)
$data = array(
“app_key” => “XXXXXX”,//應(yīng)用程序APP KEY,從阿里大于控制臺中申請
“to” => “131XXXXXXXX”,//接收短信驗(yàn)證碼的手機(jī)號碼
“s_free_sign_name” => “阿里大于”,//短信簽名
“s_template_code” => “S_XXXXX”,//短信模板ID
“s_param” => array(
//短信模板中定義的變量
“code” => rand(1000, 9999),//隨機(jī)生成驗(yàn)證碼
“product” => “阿里大于”//產(chǎn)品名稱
)
);
//構(gòu)造短信接口請求頭信息
$header = array(
“Accept: application/json”,
“User-Agent: TopSdk (PHP)”.PHP_VERSION.” SDK/2.0″,
//應(yīng)用程序APP SECRET,從阿里大于控制臺中申請
“Authorization: Top “.base64_encode(“XXXXXX:xxxxxxxxxxxxxxxxxxxxx”)
);
//創(chuàng)建curl資源
$curl = curl_init();
//設(shè)置curl請求的請求頭信息
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
//設(shè)置curl請求URL地址
curl_setopt($curl, CURLOPT_URL, $url);
//設(shè)置curl請求方式為POST
curl_setopt($curl, CURLOPT_POST, true);
//設(shè)置curl請求的post參數(shù)
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
//設(shè)置curl請求的數(shù)據(jù)格式為json
curl_setopt($curl, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json;charset=utf-8’));
//設(shè)置curl的超時時間(秒)
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
//執(zhí)行curl請求
curl_exec($curl);
//關(guān)閉curl資源
curl_close($curl);
//將生成的驗(yàn)證碼存放在SESSION中,方便后續(xù)進(jìn)行比對
$_SESSION[‘code’] = $data[‘s_param’][‘code’];
?>
需要注意的是,阿里大于短信接口中,需要傳遞應(yīng)用程序APP KEY、APP SECRET和短信模板ID等參數(shù)。其中,APP KEY和APP SECRET需要到阿里大于控制臺中申請,短信模板ID可以根據(jù)自己的業(yè)務(wù)需求到控制臺中進(jìn)行創(chuàng)建。
4.實(shí)現(xiàn)口令撞庫
當(dāng)我們對口令的撞庫進(jìn)行防范時,需要對查詢語句進(jìn)行優(yōu)化,使查詢語句的效率更高,提高一定的查詢速度,從而有效避免口令撞庫。
具體的實(shí)現(xiàn)可以采用以下方法:
1)創(chuàng)建一個用于存儲用戶數(shù)據(jù)的數(shù)據(jù)庫,將用戶的登錄名和密碼以加密的形式存儲到數(shù)據(jù)庫中。
2)分別制定用戶名和密碼的查詢語句,使用mysql_real_escape_string()函數(shù)包裝用戶的輸入,以逐一避免SQL注入攻擊。
3)結(jié)合使用MySQL中的索引功能,將用戶名和密碼的查詢進(jìn)行優(yōu)化。
4)通過批量操作能夠避免存在惡意的程序?qū)?shù)據(jù)庫進(jìn)行超負(fù)荷的查詢。
綜上所述,是一件比較細(xì)致的工作,需要我們不斷優(yōu)化查詢語句,提高查詢速度,同時還需要引入驗(yàn)證碼、短信驗(yàn)證等多種驗(yàn)證方式,這樣才能有效保障網(wǎng)站的登錄安全。
成都網(wǎng)站建設(shè)公司-創(chuàng)新互聯(lián),建站經(jīng)驗(yàn)豐富以策略為先導(dǎo)10多年以來專注數(shù)字化網(wǎng)站建設(shè),提供企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計,響應(yīng)式網(wǎng)站制作,設(shè)計師量身打造品牌風(fēng)格,熱線:028-86922220求c#注冊登錄界面源代碼(全部包括SQL數(shù)據(jù)庫)
開。。。。開玩笑啊,20分,要了多少東西。。。
以下是login.aspx.cs頁面
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username = Login1.UserName;
string pwd = Login1.Password;
string strSQL = “select LoginID from usertable where LoginID='” + username + “‘”;
if (ReDataSet(strSQL).Tables.Rows.Count = 0)
{
Response.Write(“alert(‘不存在的用戶名’)”);
}
else
{
string strSQL = “select PassWord from usertable where LoginID='” + username + “‘”;
if (ReDataSet(strSQL).Tables.Rows.Count = 0)
{
Response.Write(“alert(‘密碼錯誤’)”);
}
else
{
Response.Redirect(“../first.aspx”);
}
}
}
}
以下是login.aspx頁面
無標(biāo)題頁
棚哪數(shù)
這個是網(wǎng)頁的,不知道你是網(wǎng)頁還是程序,不過基本差不多,換湯不換藥,看看吧
我寫了一個登錄的程序,界面也做的還可以,寫了號幾天虧禪呢。20分把這么多差瞎代銷慶塵碼寫給你不太可能吧,這里也放不下
這些使用文字不好表述,是美女的話,可以視頻操作給你看哈
求用java編登錄頁面,可以連接MySql 數(shù)據(jù)庫
之一步:創(chuàng)建一個查詢過程,因?yàn)樵诘卿洉r要根據(jù)用戶名查詢用戶密碼
此步要用到pl/sql編程知識,代碼如下:
create or replace procedure sel_user(uname in varchar2,pass out varchar2) is
begin
select users.password into pass from users where users.username=uname and rownum = 1;
end;
第二步:編寫登錄頁面(login.java)(采用純java+servlet編寫)
//login.java如下
package cn.hnu;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class testhtml extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType(“text/html;charset=gbk”);
try {
PrintWriter pw = resp.getWriter();
pw.println(“”);
pw.println(“”);
pw.println(“”);
pw.println(“用戶登錄”);
pw.println(“”);
pw.println(“”);
pw.println(“”);
pw.println(“
用戶登錄
“);
pw.println(“”);
pw.println(“”);
pw.println(“用戶名:
“);
pw.println(“密  碼:
“);
pw.println(“”);
pw.println(“”);
pw.println(“”);
pw.println(“”);
pw.println(“”);
} catch (Exception e) {
e.printStackTrace();
// TODO: handle exception
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(req, resp);
}
}
第三步:編程成功登錄頁面(wel.java) //wel.java如下,它主要用于用戶正常登錄后顯示信息給用戶
package cn.hnu;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class Wel extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
//防止用戶非法登錄
HttpSession hs = req.getSession();
String s = (String)hs.getAttribute(“pass”);
if(s == null){
resp.sendRedirect(“l(fā)ogin”);
}
PrintWriter pw = resp.getWriter();
pw.write(“welcome,hello”);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(req, resp);
}
}
第四步:編寫login處理頁面(loginCl.java)
package cn.hnu;
import java.io.IOException;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class loginCl extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
String u = req.getParameter(“userName”);
String p = req.getParameter(“password”);
//查詢數(shù)據(jù)庫
String pa=null;
Connection ct = null;
CallableStatement cs = null;
try {
Class.forName(“oracle.jdbc.driver.OracleDriver”);
ct = DriverManager.getConnection(“jdbc:oracle:thin:@localhost:1521:oracle”,
“scott”, “tiger”);
cs = ct.prepareCall(“{call sel_user(?,?)}”);
cs.setString(1, u);
cs.registerOutParameter(2, oracle.jdbc.OracleTypes.VARCHAR);
cs.execute();
pa = cs.getString(2);
System.out.println(“u=” + u + ” p=” + pa);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (cs != null) {
cs.close();
}
if (ct != null) {
ct.close();
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//驗(yàn)證用戶信息是否合法
if (p.equals(pa)) {
HttpSession hs = req.getSession(true);//防止用戶非法登錄
hs.setAttribute(“pass”, “OK”);
resp.sendRedirect(“wel”);
} else {
resp.sendRedirect(“l(fā)ogin”);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doGet(req, resp);
}
}
親,sql可以換成MySQL
這個沒關(guān)系的,別的都可以照搬來用
登錄頁面的數(shù)據(jù)庫代碼的介紹就聊到這里吧,感謝你花時間閱讀本站內(nèi)容,更多關(guān)于登錄頁面的數(shù)據(jù)庫代碼,數(shù)據(jù)庫代碼實(shí)現(xiàn)網(wǎng)站登錄頁面安全驗(yàn)證,求c#注冊登錄界面源代碼(全部包括SQL數(shù)據(jù)庫),求用java編登錄頁面,可以連接MySql 數(shù)據(jù)庫的信息別忘了在本站進(jìn)行查找喔。
創(chuàng)新互聯(lián)【028-86922220】值得信賴的成都網(wǎng)站建設(shè)公司。多年持續(xù)為眾多企業(yè)提供成都網(wǎng)站建設(shè),成都品牌建站設(shè)計,成都高端網(wǎng)站制作開發(fā),SEO優(yōu)化排名推廣服務(wù),全網(wǎng)營銷讓企業(yè)網(wǎng)站產(chǎn)生價值。
當(dāng)前文章:數(shù)據(jù)庫代碼實(shí)現(xiàn)網(wǎng)站登錄頁面安全驗(yàn)證(登錄頁面的數(shù)據(jù)庫代碼)
網(wǎng)址分享:http://fisionsoft.com.cn/article/dhisdsd.html


咨詢
建站咨詢
