vb.net登陆代码,vb登录系统代码

asp.net(vb) 登录代码

protected void lkbtLogin_Click(object sender, System.EventArgs e)

创新互联建站专注于海门企业网站建设,自适应网站建设,成都做商城网站。海门网站建设公司,为海门等地区提供建站服务。全流程按需网站策划,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

{

if(txtVerifyNum.Text.Trim() != Session["SessionAppendNumber"].ToString())

{

oprtb.AlertMsg("输入的验证码错误",Page);

return;

}

DataSet ds = new DataSet();

string sql = "select UserID,Name,DepartID,CompanyID,";

sql = sql+"(select Name from Depart where ((DepartID=UserList.DepartID) and ( CompanyID=UserList.CompanyID))) as DepartName,";

sql = sql+"(select Name from Company where (CompanyID=UserList.CompanyID)) as CompanyName ";

sql = sql+"from UserList where UserID='" + txtUserID.Text.Trim() +"' and Password='" + Encrypt.EncryptPwd(txtPassword.Text.Trim(),"MD5") + "' and Cancellation = 0";

//string sql = "select * from UserList where UserID='" + txtUserID.Text.Trim() +"' and Password='" + Encrypt.EncryptPwd(txtPassword.Text.Trim(),"MD5") + "' and Cancellation = 0";

ds = oprtb.SelectTable(sql);

if (ds.Tables[0].Rows.Count = 0)

{

oprtb.AlertMsg("输入的用户名或密码错误",Page);

return;

}

else

{

string UHAddress = Request.UserHostAddress;

string currentTime = DateTime.Now.ToString("yyyyMMdd hhmmss");

//登陆成功

Session["UserID"] = ds.Tables[0].Rows[0]["UserID"].ToString();

Session["Name"] = ds.Tables[0].Rows[0]["Name"].ToString();

Session["DepartID"] = ds.Tables[0].Rows[0]["DepartID"].ToString();

Session["DepartName"] = ds.Tables[0].Rows[0]["DepartName"].ToString();

Session["CompanyID"] = ds.Tables[0].Rows[0]["CompanyID"].ToString();

Session["CompanyName"] = ds.Tables[0].Rows[0]["CompanyName"].ToString();

//设置用户的登陆时间

oprtb.SetStartTime(txtUserID.Text.Trim());

//设置用户的登陆标记

string s_mark = txtUserID.Text.Trim() + "_" + UHAddress + "_" + currentTime;

oprtb.SetLoginMark(s_mark,txtUserID.Text.Trim());

//保存登陆标记

Session["LoginMark"] = s_mark;

MCompany.SystemLog slstru = new YesErp.MCompany.SystemLog();

slstru.SystemLog_IP = UHAddress;

slstru.SystemLog_LogIn = System.DateTime.Now;

slstru.SystemLog_Name = ds.Tables[0].Rows[0]["Name"].ToString();//用户姓名

slstru.SystemLog_ID = Int32.Parse(ds.Tables[0].Rows[0]["UserID"].ToString());//用户ID

//写系统日志

oprtb.LoginSystemLog(slstru);

//oprtb.AlertMsg("登录成功",Page);

Session["LoginTime"] = System.DateTime.Now;

//判断并转到新的页面

oprtb.ChangeUrl("../index.aspx",Page);

}

}

vb.net 用户登录

哈哈简单哪

第一步:登陆网页代码

第二步:登陆以后判断是否登陆成功

有两种方法:1.获取网页代码,判断网页字符有无”登陆成功”字样

源代码:

2.就是判断网页是否跳转到了某一页

源代码:

两种方法结合起来用,可以判断网页是否无法连接

如何用VB.NET制作账号自动登陆的程序

Private Sub SendBlogTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendBlogTimer.Tick

Dim textboxUserId As HtmlElement

Dim textboxPassword As HtmlElement

Dim buttonSubmit As HtmlElement

textboxUserId = SendBlogBrowser.Document.All("username")'获取用户名输入框

textboxPassword = SendBlogBrowser.Document.All("password")'获取密码输入框

buttonSubmit = SendBlogBrowser.Document.All("btnLogin")'获取登陆按钮

textboxUserId.SetAttribute("value","用户名")'给用户名输入框赋值

textboxPassword.SetAttribute("value","密码")'给密码框赋值

buttonSubmit.InvokeMember("click")’执行登陆按钮的单击

End Sub

其中的SendBlogBrowser为WebBrowser控件

vb语言asp.net登陆代码 急

人家要vb的。。。一楼的不地道。

Partial Class Login

Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

btnLogin.Enabled = True

lblMsg.Text = ""

If Session("loginName") "" Then

btnLogin.Enabled = False

lblMsg.Text = "Please Logout first."

End If

txtName.Focus()

End Sub

Protected Sub btnlogin_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogin.Click

Dim objDBUser As New cDBUser

If objDBUser.checkLoginName(txtName.Text) = 1 Then

Dim accessLv As Integer = objDBUser.checkPassword(txtName.Text, txtPwd.Text)

If accessLv = -1 Then

lblMsg.Text = "Wrong Password. Please try again."

txtPwd.Focus()

ElseIf accessLv = 0 Then

lblMsg.Text = "Your account is locked. Contact with site admin."

Else

lblMsg.Text = "Login successfully."

Dim loginName As String = txtName.Text

Session.Add("loginName", loginName)

Session.Add("userName", objDBUser.getUserName(loginName))

Response.Redirect("Index.aspx")

End If

Else

lblMsg.Text = "Wrong Login Name."

txtName.Focus()

End If

End Sub

Protected Sub btnLogout_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnLogout.Click

Session.Clear()

End Sub

End Class

这个是code behind file

另外需要在app code 里面放一个叫dbUser和Cuser的class

Imports Microsoft.VisualBasic

Imports System.Data.SqlClient

Imports System.Data

Public Class cDBUser

Private conn As New SqlConnection

Private connstr As String = System.Configuration.ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString

Private sqlCmd As New SqlCommand

Public Sub New()

conn.ConnectionString = connstr

sqlCmd.Connection = conn

End Sub

Public Function checkLoginName(ByVal loginName As String) As Integer

Try

conn.Open()

sqlCmd.CommandText = "SELECT COUNT(password) FROM tblUser where LoginName = '" loginName "'"

Return sqlCmd.ExecuteScalar

Catch ex As Exception

MsgBox(ex.Message)

Return 0

Finally

conn.Close()

End Try

End Function

Public Function checkPassword(ByVal loginName As String, ByVal pwd As String) As Integer

Try

conn.Open()

sqlCmd.CommandText = "SELECT COUNT(*) FROM tblUser WHERE loginName = '" loginName _

"' and password = '" pwd "'"

Dim passwordOK As Integer = sqlCmd.ExecuteScalar

If passwordOK = 1 Then

sqlCmd.CommandText = "SELECT accesslevel FROM tblUser WHERE loginName = '" loginName _

"' and password = '" pwd "' and status = 1"

Return CInt(sqlCmd.ExecuteScalar)

Else

Return -1

End If

Catch ex As Exception

MsgBox(ex.Message)

Return 0

Finally

conn.Close()

End Try

End Function

Public Function getOldPwd(ByVal loginName As String) As String

Try

conn.Open()

sqlCmd.CommandText = "SELECT Password FROM tblUser WHERE LoginName = '" loginName "'"

Return sqlCmd.ExecuteScalar

Catch ex As Exception

MsgBox(ex.Message)

Return Nothing

Finally

conn.Close()

End Try

End Function

Public Function getUserName(ByVal loginName As String) As String

Try

conn.Open()

sqlCmd.CommandText = "SELECT UserName FROM tblUser WHERE LoginName = '" loginName "'"

Return sqlCmd.ExecuteScalar

Catch ex As Exception

MsgBox(ex.Message)

Return Nothing

Finally

conn.Close()

End Try

End Function

Public Function getAllUsers() As DataView

Try

conn.Open()

Dim sqlAdpt As New SqlDataAdapter("SELECT userID,LoginName,UserName,Email,AccessLevel,Status FROM tblUser", connstr)

Dim dt As New DataTable

sqlAdpt.Fill(dt)

Return dt.DefaultView

Catch ex As Exception

MsgBox(ex.Message)

Return Nothing

Finally

conn.Close()

End Try

End Function

Public Function getUserDetails(ByVal loginName As String) As cUser

Try

conn.Open()

Dim sqlAdpt As New SqlDataAdapter("SELECT * from tblUser where loginName = '" loginName "'", connstr)

Dim dt As New DataTable

sqlAdpt.Fill(dt)

Dim dr As DataRow = dt.Rows(0)

Dim objUser As New cUser

objUser.userId = dr.Item("UserId")

objUser.loginName = dr.Item("LoginName")

objUser.password = dr.Item("Password")

objUser.userName = dr.Item("UserName")

objUser.Email = dr.Item("Email")

objUser.accessLevel = dr.Item("AccessLevel")

objUser.status = dr.Item("Status")

Return objUser

Catch ex As Exception

MsgBox(ex.Message)

Return Nothing

Finally

conn.Close()

End Try

End Function

Public Function changeUserStatus(ByVal userId As Integer) As Integer

Try

conn.Open()

sqlCmd.CommandText = "UPDATE tblUser SET status = (1 - status) WHERE userId = " userId

Return CInt(sqlCmd.ExecuteScalar)

Catch ex As Exception

MsgBox(ex.Message)

Return 0

Finally

conn.Close()

End Try

End Function

Public Function changeEmail(ByVal loginName As String, ByVal newEmail As String) As Integer

Try

conn.Open()

sqlCmd.CommandText = "UPDATE tblUser SET Email = '" newEmail "' WHERE LoginName = '" loginName "'"

Return sqlCmd.ExecuteNonQuery

Catch ex As Exception

MsgBox(ex.Message)

Return 0

Finally

conn.Close()

End Try

End Function

Public Function changePwd(ByVal loginName As String, ByVal newPwd As String) As Integer

Try

conn.Open()

sqlCmd.CommandText = "UPDATE tblUser SET password = '" newPwd "' WHERE loginName = '" loginName "'"

Return sqlCmd.ExecuteNonQuery

Catch ex As Exception

MsgBox(ex.Message)

Return 0

Finally

conn.Close()

End Try

End Function

Public Function addUser(ByVal objUser As cUser) As Integer

Try

conn.Open()

sqlCmd.CommandText = "INSERT INTO tblUser (userName,loginName,password,email,accessLevel,status) VALUES('" _

Trim(objUser.userName) "','" Trim(objUser.loginName) "','" objUser.password "','" Trim(objUser.Email) "','" _

objUser.accessLevel "',1)"

If sqlCmd.ExecuteNonQuery() = 1 Then

sendEmail()

Return 1

End If

Catch ex As Exception

MsgBox(ex.Message)

Return 0

Finally

conn.Close()

End Try

End Function

Public Function retrievePwd(ByVal loginName As String) As Integer

Try

conn.Open()

sqlCmd.CommandText = "SELECT password from tblUser where loginName = '" loginName "'"

Dim pwd As String = sqlCmd.ExecuteScalar

Dim email As String = getEmail(loginName)

If email "" And pwd "" Then

sendEmail()

Return 1

Else

Return 0

End If

Catch ex As Exception

MsgBox(ex.Message)

Return 0

Finally

conn.Close()

End Try

End Function

Public Function getEmail(ByVal loginName As String) As String

conn.Close()

Try

conn.Open()

sqlCmd.CommandText = "SELECT Email from tblUser where loginName = '" loginName "'"

Dim email As String = sqlCmd.ExecuteScalar

Return email

Catch ex As Exception

MsgBox(ex.Message)

Return ""

Finally

conn.Close()

End Try

End Function

Private Sub sendEmail()

'some code here to send email

End Sub

End Class

Imports Microsoft.VisualBasic

Public Class cUser

Private intUserId As Integer

Private strUserName As String

Private strLoginName As String

Private strPassword As String

Private strEmail As String

Private shortAccessLevel As Short

Private byteStatus As Byte

Public Sub New()

End Sub

Public Property userId() As Integer

Get

Return intUserId

End Get

Set(ByVal value As Integer)

intUserId = value

End Set

End Property

Public Property userName() As String

Get

Return strUserName

End Get

Set(ByVal value As String)

strUserName = value

End Set

End Property

Public Property loginName() As String

Get

Return strLoginName

End Get

Set(ByVal value As String)

strLoginName = value

End Set

End Property

Public Property password() As String

Get

Return strPassword

End Get

Set(ByVal value As String)

strPassword = value

End Set

End Property

Public Property Email() As String

Get

Return strEmail

End Get

Set(ByVal value As String)

strEmail = value

End Set

End Property

Public Property accessLevel() As String

Get

Return shortAccessLevel

End Get

Set(ByVal value As String)

shortAccessLevel = value

End Set

End Property

Public Property status() As Byte

Get

Return byteStatus

End Get

Set(ByVal value As Byte)

byteStatus = value

End Set

End Property

End Class

vb.net 连接SQL数据库登录代码

问题应该出在你的查询语句的结果没有值,你用你的查询语句到SQL中是否有返回值?记得加上你的条件,另外,你语句里这一句是多余的.Dim s As Object = sComm.ExecuteScalar 以下语句测试正常 Dim myCn As New SqlClient.SqlConnection Try myCn.ConnectionString = sConnString myCn.Open() Dim mySQL As String = "SELECT * FROM ygzl" Dim sComm As New SqlClient.SqlCommand(mySQL, myCn) If sComm.ExecuteScalar Then Dim User_MainForm As New Form1 User_MainForm.Show() Else MsgBox("用户名或密码不正确,请重试!") End If Catch ex As Exception MsgBox(ex.Message) Finally myCn.Close() '关闭连接 End Try

在vb.net 里怎么新建SQL数据库里的登录,给我代码,谢谢

1.创建用户 create user 新建用户 密码

2.将登录的权限分配给新建的用户

grant login to 新建用户

我这里写的代码没有测试,需要具体测试修改一下,^_^

思路就是这样,

呵呵,希望能有帮助,^_^


新闻标题:vb.net登陆代码,vb登录系统代码
本文路径:http://ybzwz.com/article/dsiepjp.html