資料庫登錄頁面
1. ASP連接資料庫時,登錄頁面(login)用戶名和密碼在資料庫哪裡
資料庫用sqlserver.在asp頁面中設置提交後的處理頁面為checkuser.asp.在checkuser.asp比較request中原來輸入的登錄用戶名和密碼,然後訪問sqlserver中的用戶名和密碼,如果符合就完成驗證。代碼如下
admin=trim(request("userName"))
password=trim(request("password"))
if admin=""or password=""then
response.Write"<center><a href=login.asp><font color=red size=2>對不起,錄失敗,請檢查您的登錄名和密碼</font></a></center>"
response.end
end if
set cn=Opendatabase'打開資料庫
set rs=server.CreateObject("adodb.recordset")
rs.ActiveConnection=cn
rs.Source="select * from userInfo where userno='"&admin&"'and userpwd='"&password&"'"
'rs.CursorType=1
'rs.LockType=1
'打開記錄集
rs.Open()
'rs.Open "select * from userInfo where userName='"&admin&"'and password='"&password&"'",cn,1,1
if not(rs.bof and rs.eof)then
if password=trim(rs("userpwd"))then
session("admin")=trim(rs("userno"))
session("flag")=rs("flag")
session("employeeid")= rs("sno")
session.Timeout=20
rs.Close
set rs=nothing
set cn=nothing
response.Redirect"index.asp"
else
response.write"<script LANGUAGE='javascript'> alert('對不起,登錄失敗!');history.go(-1);</script>"
end if
else
response.write"<script LANGUAGE='javascript'>alert('對不起,登錄失敗!');history.go(-1);</script>"
End if
2. Android studio怎麼連接本地資料庫設計登錄界面
我們項目的前提是你已經將基本的運行環境及sdk都已經安裝好了,讀者可自行網路環境配置相關內容,本文不再贅述。右鍵點擊new-->Mole,Mole相當於新建了一個項目。
選擇Android Application,點擊next
將My Mole 和app改成自己項目相應的名字,同時選擇支持的Android版本
這一步我們選擇Blank Activity,自己手動編寫登錄界面,而不依賴系統內置的Login Activity,一直點擊next,最後點擊finish就完成了項目的創建
在project下我們可以看到出現了我們剛才創建的login項目
展開res/layout,點擊打開activity_main.xml文件,在這個文件里我們將完成登錄界面的編寫
這是初始的主界面,還沒有經過我們編寫的界面,Android Studio有一個很強大的預覽功能,相當給力,將activity_main.xml的代碼替換成如下代碼:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:stretchColumns="0,3">
<TableRow>
<TextView />
<TextView
android:text="賬 號:"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="24px"
/>
<EditText
3. 我用access做了個資料庫系統,現在想做一個登錄頁面,請問如何設置訪問需用戶名和密碼才能登錄。
這個先在資料庫里建一張表,一列是用戶名,一列是密碼。然後做一個登錄的頁面,然後鏈接資料庫。這樣同過在頁面中寫代碼,判斷輸入的用戶名在資料庫中有沒有,如果有,再判斷對應的密碼正確否。如果正確,就跳轉到另外一個頁面(就是你成功登陸後的頁面),不正確提示錯誤。
4. 怎樣用 myeclipse和資料庫做一個簡單的登錄界面,用來完成對資料庫的操作
首先用myeclipse創建一個web 工程
這是jsp登錄頁面
<body>
<%
request.setCharacterEncoding("GBK");
String name=request.getParameter("文件名");
if(name.equals("sa")){
session.setAttribute("UserName",name);
response.sendRedirect("文件名");
}
else{
response.sendRedirect("文件名");
}
%>
</body>
連接資料庫文件
public class ConnectionManager {
private static final String DRIVER_CLASS = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
private static final String DATABASE_URL = "jdbc:sqlserver://localhost:1433;DatabaseName="資料庫名「;
private static final String DATABASE_USRE = "sa";
private static final String DATABASE_PASSWORD = "sa";
/**
* 返回連接
*
* @return Connection
*/
public static Connection getConnection() {
Connection dbConnection = null;
try {
Class.forName(DRIVER_CLASS);
dbConnection = DriverManager.getConnection(DATABASE_URL,
DATABASE_USRE, DATABASE_PASSWORD);
} catch (Exception e) {
e.printStackTrace();
}
return dbConnection;
}
/**
* 關閉連接
*
* @param dbConnection
* Connection
*/
public static void closeConnection(Connection dbConnection) {
try {
if (dbConnection != null && (!dbConnection.isClosed())) {
dbConnection.close();
}
} catch (SQLException sqlEx) {
sqlEx.printStackTrace();
}
}
/**
* 關閉結果集
*/
public static void closeResultSet(ResultSet res) {
try {
if (res != null) {
res.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
/**
* 關閉語句
*/
public static void closeStatement(PreparedStatement pStatement) {
try {
if (pStatement != null) {
pStatement.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}
}
5. 求助一個C#web做的一個連接資料庫的登陸界面
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace TakeSys
{
public partial class Frm_Login : Form
{
int j = 0;
int flag;
string sid, pwd;
public Frm_Login()
{
InitializeComponent();
}
public static Frm_Login f1;
private void Frm_Login_Load(object sender, EventArgs e)
{
f1 = this;
}
private void bLogin_Click(object sender, EventArgs e)
{
pwd = tPwd.Text;
sid = tSid.Text;
if (sid.Trim() == "")
{
MessageBox.Show("賬號不能為空!");
}
if (pwd.Trim() == "")
{
MessageBox.Show("密碼不能為空!");
}
else
{
LoginEnter(sid,pwd);
}
}
//解鎖
private void bUnlock_Click(object sender, EventArgs e)
{
int i = 0;
string str = "server=192.168.7.40;database=TakesDb;uid=sa;pwd=windows,./2013";
SqlConnection con = new SqlConnection(str);
try
{
con.Open();
string sqlstr = "select FLAG from tLogin where Sid=@sid";
SqlDataAdapter sda = new SqlDataAdapter(sqlstr, con);
sda.SelectCommand.Parameters.Add("@sid", SqlDbType.VarChar).Value = sid;
DataSet aa = new DataSet();
sda.Fill(aa);
flag = int.Parse(aa.Tables[0].Rows[0]["FLAG"].ToString());
if (flag > 2)
{
string sqlflag = "UPDATE TLOGIN SET FLAG=0 WHERE Sid=@sid";
SqlDataAdapter sdf = new SqlDataAdapter(sqlflag, con);
sdf.SelectCommand.Parameters.Add("@sid", SqlDbType.VarChar).Value = sid;
i = sdf.SelectCommand.ExecuteNonQuery();
if (i == 1)
{
MessageBox.Show("解鎖成功!");
}
else
{
MessageBox.Show("解鎖失敗!");
}
}
else
{
MessageBox.Show("您的帳號未被鎖定,不需解鎖!");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
con.Close();
con.Dispose();
}
}
//登錄
private void LoginEnter(string sid,string pwd)
{
int k = 0;
string str = "server=192.168.7.40;database=TakesDb;uid=sa;pwd=windows,./2013";
SqlConnection con = new SqlConnection(str);
try
{
con.Open();
string sqlstr = "select PWD,FLAG from TLOGIN where SID=@sid";
SqlDataAdapter sda = new SqlDataAdapter(sqlstr, con);
sda.SelectCommand.Parameters.Add("@sid", SqlDbType.VarChar).Value = sid;
DataSet aa = new DataSet();
sda.Fill(aa);
flag = int.Parse(aa.Tables[0].Rows[0]["FLAG"].ToString());
if (flag > 2)
{
MessageBox.Show("您的帳號已被鎖定!!!");
}
else if (pwd == aa.Tables[0].Rows[0]["pwd"].ToString())
{
if (flag != 0)
{
string sqlflag = "UPDATE TLOGIN SET FLAG=0 WHERE SID=@sid";
SqlDataAdapter sdf = new SqlDataAdapter(sqlflag, con);
sdf.SelectCommand.Parameters.Add("@sid", SqlDbType.VarChar).Value = sid;
sdf.SelectCommand.ExecuteNonQuery();
}
this.DialogResult = DialogResult.OK;
this.Close();
}
else
{
string sqlflag = "UPDATE TLOGIN SET FLAG=FLAG+1 WHERE SID=@sid";
SqlDataAdapter sdf = new SqlDataAdapter(sqlflag, con);
sdf.SelectCommand.Parameters.Add("@sid", SqlDbType.VarChar).Value = sid;
k = sdf.SelectCommand.ExecuteNonQuery();
if (k == 1)
{
j++;
}
if (j == 3)
{
MessageBox.Show("三次密碼輸入錯誤,您的帳號已被鎖定!!!");
}
else
{
MessageBox.Show("密碼錯誤!");
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
finally
{
con.Close();
con.Dispose();
}
}
private void Login_KeyDoen(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
bLogin_Click(sender,e);
}
}
}
}
6. 用access資料庫建一個用戶表,做一個登錄界面,通過asp查詢用戶表的方法,實現對合法用戶的判斷
1,首先鏈接資料庫
2,根據輸入的用戶名去查詢資料庫中的密碼(通常密碼用MID5加密)
3,將用戶輸入的密碼加密後和資料庫中取出的比對
4.如果比對成功,就建立一個session對象,網站各頁面裝入前首先驗證這個session對象,如果存在就正常訪問,如果不存在這個session對象就跳轉到登錄頁面。
上面是登錄頁面的常見做法,做深入了還要考慮防止SQL注入攻擊,驗證碼防止暴力破解等。
你哪步不會說,我給你搞代碼。
不要說都不會