Files
VERAG_Homepage/login/login_FLEX.aspx.vb
2021-10-20 11:25:30 +02:00

157 lines
7.2 KiB
VB.net

Imports System.Data.SqlClient
Imports System.Data
Partial Class login_FLEX
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub ValidateUser(sender As Object, e As EventArgs)
Dim userId As Integer = 0
' cDBFunctions.GetNewOpenConnection()
Dim ConnectionString = ""
If HttpContext.Current.Request.ServerVariables("SERVER_NAME") = "localhost" Then
'ConnectionString = "Server=DEVELOPER\DEVSQL;Database=VERAG_HOMEPAGE;Uid=sa;Pwd=BmWr501956"
ConnectionString = "Server=DEVELOPER\DEVSQL;Database=VERAG_HOMEPAGE;Uid=AppUser;Pwd=yp/THDd?xM+pZ$;"
Else
ConnectionString = "Server=DEVELOPER.verag.ost.dmn\DEVSQL;Database=VERAG_HOMEPAGE;Uid=AppUser;Pwd=yp/THDd?xM+pZ$;"
'ConnectionString = "Server=db593295684.db.1and1.com;Database=db593295684;Uid=dbo593295684;Pwd=atilla#2;"
End If
Dim tb As TextBox = form1.FindControl("txt_CustomerID")
Dim tb_M As TextBox = form1.FindControl("txt_CustomerID_M")
Dim tb2 As TextBox = form1.FindControl("UserName")
Dim tb2_M As TextBox = form1.FindControl("UserName_M")
Dim tb3 As TextBox = form1.FindControl("Password")
Dim tb3_M As TextBox = form1.FindControl("Password_M")
Dim reqfieldvaluserID As RequiredFieldValidator = Page.FindControl("CustomerIDrequired")
Dim reqfieldvaluserID_M As RequiredFieldValidator = Page.FindControl("CustomerID_M_required")
Dim reqfieldvaluserName As RequiredFieldValidator = Page.FindControl("UserNamerequired")
Dim reqfieldvaluserName_M As RequiredFieldValidator = Page.FindControl("UserName_M_required")
Dim reqfieldvalpassw As RequiredFieldValidator = Page.FindControl("Passwordrequired")
Dim reqfieldvalpassw_M As RequiredFieldValidator = Page.FindControl("Passwordrequired_M")
Dim regexuserID As RegularExpressionValidator = Page.FindControl("valid_getNumberInput")
Dim regexuserID_M As RegularExpressionValidator = Page.FindControl("valid_getNumber_M_Input")
Dim regexusername As RegularExpressionValidator = Page.FindControl("check_UserName_regex")
Dim regexusername_M As RegularExpressionValidator = Page.FindControl("check_UserName_M_regex")
Dim Customer_ID As String = String.Empty
Dim UserNaMe As String = String.Empty
Dim passw As String = String.Empty
If reqfieldvaluserID.IsValid Then
regexuserID.Validate()
If regexuserID.IsValid Then
Customer_ID = tb.Text
End If
ElseIf reqfieldvaluserID_M.IsValid Then
regexusername_M.Validate()
If regexusername_M.IsValid Then
Customer_ID = tb_M.Text
End If
End If
If reqfieldvaluserName.IsValid Then
UserNaMe = tb2.Text
ElseIf reqfieldvaluserName_M.IsValid Then
UserNaMe = tb2_M.Text
End If
If reqfieldvalpassw.IsValid Then
passw = tb3.Text
ElseIf reqfieldvaluserName_M.IsValid Then
passw = tb2_M.Text
End If
' Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(ConnectionString)
' Using cmd As New SqlCommand("Validate_User")
Using cmd As New SqlCommand("SELECT COUNT(*), UserId,Username, Password FROM [VERAG_HOMEPAGE].[dbo].[Users] WHERE Username=@Username AND Password=@Password AND Kundennr=@Kundennr")
' cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@Username", UserNaMe)
cmd.Parameters.AddWithValue("UserID", Customer_ID)
cmd.Parameters.AddWithValue("@Password", passw)
cmd.Connection = con
con.Open()
' userId = Convert.ToInt32(cmd.ExecuteScalar())
Dim dr As SqlDataReader = cmd.ExecuteReader()
If dr.HasRows Then
dr.Read()
'MsgBox(dr.Item(0).ToString())
Select Case dr.Item(0)
Case 0
Login1.FailureText = "Benuzername und/oder das Passwort stimmen nicht überein."
Exit Select
Case -2
Login1.FailureText = "Account ist nicht freigeschaltet."
Exit Select
Case Else
If tb.Text = dr("UserId") Then
Customer_ID = dr("UserId")
Else
Login1.FailureText = "ID cannot be found in the database!"
End If
If tb2.Text = dr("Username") Then
Customer_ID = dr("Username")
Else
Login1.FailureText = "Username is not in the database!"
End If
If tb3.Text = dr("Password") Then
Customer_ID = dr("Password")
Else
Login1.FailureText = "Password is not in the database!"
End If
Login1.FailureText = "Erfolgreich validiert."
Session.Add("test", UserNaMe)
Session.Add("UserID", Customer_ID)
Session.Add("PW", passw)
FormsAuthentication.RedirectFromLoginPage(UserNaMe, True)
'FormsAuthentication.SetAuthCookie(Login1.UserName, True)
'Response.Redirect("../Customers/CustomsAviso.aspx")
Exit Select
End Select
End If
dr.Close()
con.Close()
End Using
End Using
End Sub
Protected Sub LoginButton_Click(sender As Object, e As EventArgs)
Validate("Login")
If Page.IsValid() Then
MsgBox("Wow1")
Dim cb As CheckBox = Page.FindControl("RememberMe")
If cb.Checked = True Then
FormsAuthentication.SetAuthCookie(Login1.UserName, True)
Else
FormsAuthentication.SetAuthCookie(Login1.UserName, False)
End If
Response.Redirect("../Customers/CustomsAviso.aspx")
Else
MsgBox("Error1")
Response.Redirect("login_FLEX.aspx")
End If
End Sub
Protected Sub LoginButton_M_Click(sender As Object, e As EventArgs)
Validate("Login_M")
If Page.IsValid() Then
MsgBox("Wow2")
Dim cb As CheckBox = Page.FindControl("RememberMe_M")
If cb.Checked = True Then
FormsAuthentication.SetAuthCookie(Login1.UserName, True)
Else
FormsAuthentication.SetAuthCookie(Login1.UserName, False)
End If
Response.Redirect("../Customers/CustomsAviso.aspx")
Else
MsgBox("Error2")
Response.Redirect("login_FLEX.aspx")
End If
End Sub
End Class