how to create log in password in vb encrypted - vb.net

Hi i have been searching the internet for 3 weeks now on how to create a log in interface with encrypted password . I was a to encrypt the text box for password but I dont know how to implement it . I am using linq to sql dbml to connect to my data based on text only I was able to get it can create but I want it to be more secure and more professionally looking with encrypted one. By the way I used wizard for creating database not hard coded it that is the way I know how to do it. I am totally noob in programming any help will do. Thanks
Public Class User_Log_In_v7
Dim admin As New GeneralsDataContext
Private Sub User_Log_InBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Me.Validate()
Me.User_Log_InBindingSource.EndEdit()
Me.TableAdapterManager.UpdateAll(Me.User_Log_In_DataSet)
End Sub
Private Sub User_Log_In_v7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'User_Log_In_DataSet.User_Log_In' table. You can move, or remove it, as needed.
'Me.User_Log_InTableAdapter.Fill(Me.User_Log_In_DataSet.User_Log_In)
End Sub
Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click
Try
Dim check = From Storage In admin.User_Log_Ins _
Where UsernameTextBox.Text = Storage.Username And PasswordTextBox.Text = Storage.Password
If Not check.Count = 0 Then
Membership_Information.Show()
Me.Hide()
UsernameTextBox.Text = ""
PasswordTextBox.Text = ""
Else
MsgBox("Please check username or password and try again", MsgBoxStyle.Exclamation, "")
UsernameTextBox.Text = ""
PasswordTextBox.Text = ""
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
This is the code I can from another tutorial for encrypting
Imports System.Security.Cryptography
Imports System.Text
Public Class Form1
Dim DES As New TripleDESCryptoServiceProvider
Dim MD5 As New MD5CryptoServiceProvider
'hash function
Function MD5Hash(value As String) As Byte()
Return MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(value))
End Function
'Encryption
Function Encrypt(input As String, Key As String) As String
DES.Key = MD5Hash(Key)
DES.Mode = CipherMode.ECB
Dim buffer As Byte() = ASCIIEncoding.ASCII.GetBytes(input)
Return Convert.ToBase64String(DES.CreateEncryptor().TransformFinalBlock(buffer, 0, buffer.Length))
End Function

Related

Visual Basic time synchronizing

I am working oin a project in vb.net although I am not an expert in it, I just used it because U think it is the best for this kind of problem.
I have a project with two buttons and a label; first button is for sync windows date from a server and the other is to change the windows date to (2014, 11, 16). I am doing this because some programs I have doesn't run unless the date is this one and as you know browser must be the real time to run this is the idea of this project.
The second button is working perfectly, but the sync date button doesn't work and throws this error in my label
No connection because the target machine refused to connect
Here is my function and my server ip
Public Function GetNISTTime(ByVal host As String) As String
Dim timeStr As String = ""
Try
Dim reader As New StreamReader(New TcpClient(host, 13).GetStream)
LastSysTime = DateTime.UtcNow()
timeStr = reader.ReadToEnd()
reader.Close()
Catch ex As SocketException
GetNISTTime = ex.Message
Exit Function
Catch ex As Exception
GetNISTTime = ex.Message
Exit Function
End Try
'Dim jd As Integer = Integer.Parse(timeStr.Substring(1, 5))
'Dim yr As Integer = Integer.Parse(timeStr.Substring(7, 2))
'Dim mo As Integer = Integer.Parse(timeStr.Substring(10, 2))
'Dim dy As Integer = Integer.Parse(timeStr.Substring(13, 2))
'Dim hr As Integer = Integer.Parse(timeStr.Substring(16, 2))
'Dim mm As Integer = Integer.Parse(timeStr.Substring(19, 2))
'Dim sc As Integer = Integer.Parse(timeStr.Substring(22, 2))
'Dim Temp As Integer = CInt(AscW(timeStr(7)))
Return timeStr ' New DateTime(yr + 2000, mo, dy, hr, mm, sc)
End Function
and the button
Private Sub real_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles real.Click
GetNISTTime("mail.harf.com.sa")
Label1.Text = GetNISTTime("mail.harf.com.sa").ToString
End Sub
I think the problem is because of the server but I didn't find any dns server that does sync successfully.
This is my program download link if you want to see the problem in with your eyes (you should run it as adminstrator)
http://www.mediafire.com/file/wfw5jpag8w2hofb/Release.rar/file
Also it must be dns in Saudi Arabia time zone
Your function call is not correct.
Private Sub real_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles real.Click
GetNISTTime("mail.harf.com.sa")
Label1.Text = GetNISTTime("mail.harf.com.sa").ToString
End Sub
should be:
Private Sub real_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles real.Click
Label1.Text = GetNISTTime("mail.harf.com.sa")
End Sub
GetNISTTime is a function that returns a string, so your original first line (GetNISTTime("mail.harf.com.sa")) does the work but nothing is done with the return value. Your original second line takes a return value that is a string and then tries to convert it to a string.
In addition, your function may not return anything if an error occurs. You have used a VBA style assignment in the catch block. Instead, try:
Public Function GetNISTTime(ByVal host As String) As String
Dim timeStr As String = ""
Try
Dim reader As New StreamReader(New TcpClient(host, 13).GetStream)
LastSysTime = DateTime.UtcNow()
timeStr = reader.ReadToEnd()
reader.Close()
Catch ex As SocketException
return ex.Message
Catch ex As Exception
Return ex.Message
End Try
'any other stuff
Return timeStr
End Function
so i did like what Visual Vincent say and this is my code after editing it
and it worked perfectly with me just need administrator permissions
code
Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Runtime.InteropServices
Public Class Daytime
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim d As DateTime
d = "12:52:00"
Try
Microsoft.VisualBasic.TimeOfDay = d 'Your time...
Microsoft.VisualBasic.DateString = New Date(2014, 11, 16) 'The date...
Catch ex As Exception
'You might have to run as Administrator...?
End Try
End Sub
Private Sub real_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles real.Click
Process.Start("CMD", "/C net start w32time & w32tm /resync /force & pause")
End Sub
End Class

Invalid cast Eception unhandled by user code in vb.net

I run the site following errors occured:
System.InvalidCastException was unhandled by user code
Message="Conversion from string "kumar" to type 'Short' is not valid."
Imports System.Data.OleDb
Namespace wbdsproject
Partial Class frmprofile
Inherits System.Web.UI.Page
Dim proCon As OleDbConnection
Dim proCmd As OleDbCommand
Dim prodr As OleDbDataReader
Dim username As String
Dim userid As Int16
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load
'Put user code to initialize the page here
' maillink.NavigateUrl = "mailto:saranya#gmail.com"
Dim proselqry As String
username = Session("loginuser")
lblusername.Text = username
userid = Request.QueryString("userid")
'Response.Write(userid)
proCon = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Discussion Forum\database-WBDS\SampleForum.mdb")
proCon.Open()
If Session("loginuser") = "" Then
Response.Redirect("frmlogin.aspx")
End If
proselqry = "select * from tblprofile where uid='" & userid & "'"
proCmd = New OleDbCommand(proselqry, proCon)
proCmd.ExecuteNonQuery()
prodr = proCmd.ExecuteReader
If prodr.Read Then
lbldob.Text = prodr("dob")
lblquali.Text = prodr("quali")
lblinterest.Text = prodr("interest")
lbladdress.Text = prodr("address")
maillink.Text = prodr("emailid")
maillink.NavigateUrl = "mailto:" & prodr("emailid")
lblzip.Text = prodr("zip")
lblphno.Text = prodr("phno")
End If
End Sub
Private Sub btnmodify_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmodify.Click
Response.Redirect("frmregmodify.aspx?user=" & username & "&userid=" & userid & "&page=frmprofile")
End Sub
Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
End Class
End Namespace
at Microsoft.VisualBasic.CompilerServices.Conversions.ToShort(String Value)
You're trying to cast a String returning function into a Int16 in this line
userid = Request.QueryString("userid")
Apparently, your return is not numeric. You can either change that from the source if you have control over it or change change the userid type to string.
I would suggest using a user defined function to test if the requesting querty string is numeric before casting to an Int16 datatype.

VB2010 & MSACCESS | Object reference not set to an instance of an object

i'm making a login form and every time i try to login(whether with a correct or not user) it gives me the same error.
"Object reference not set to an instance of an object"
Here's the code:
Public Class login
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Fausto\Documents\GitHub\CRE\cre.accdb;")
Dim sql As String = "SELECT USERID FROM USERS WHERE USERID=#p_userid AND PASSWORD=#p_passw;"
Dim cmd As New OleDb.OleDbCommand(sql, conn)
Dim da As New OleDb.OleDbDataAdapter
Private Sub login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'I figured how to make comments in VB! Yeey
'Temporarely redirecting to menuForm
With cmd
.Parameters.AddWithValue("p_userid", username.Text)
.Parameters.AddWithValue("p_passw", password.Text)
End With
Try
conn.Open()
Dim usr As String = cmd.ExecuteScalar.ToString
If Not (IsDBNull(usr)) AndAlso usr = username.Text Then
Me.DialogResult = Windows.Forms.DialogResult.OK
Else
Me.DialogResult = Windows.Forms.DialogResult.Cancel
End If
Catch ex As Exception
MsgBox("Could not connect to DB hahahaha" & Environment.NewLine & "Error message: " & ex.Message)
Me.DialogResult = Windows.Forms.DialogResult.Cancel
Finally
conn.Close()
Me.Close()
End Try
End Sub
Private Sub closeBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closeBtn.Click
End
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
credits.Show()
End Sub
End Class
I'm using Visual Basic Express and Microsoft Access 2010,
Thanks :D
I saw several issues, but I think the one addressed in the question is here:
Dim conn As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=C:\Users\Fausto\Documents\GitHub\CRE\cre.accdb;")
Dim sql As String = "SELECT USERID FROM USERS WHERE USERID=#p_userid AND PASSWORD=#p_passw;"
Dim cmd As New OleDb.OleDbCommand(sql, conn)
The problem is that those variables are class-level, initialized prior to the class constructor, and the order in which the variables are initialized is not guaranteed. What is happening is that, at the point when the New OleDb.OleDbCommand(sql, conn) code executes, the conn variable is not guaranteed to have initialized.
This omission will fly under the radar, all the way until you try to execute a command, here:
Dim usr As String = cmd.ExecuteScalar.ToString
Aside from needing parentheses for the function call, it's not unil this point that the OleDbCommand object finally tries to use the connection supplied earlier and discovers that there's Nothing there.
While I have your attention, I also need to point out that you're using the wrong parameter notation for OleDb (you need to use ? placeholders instead of #NameParameters). Also, this is a horrible way to handle authentication. NEVER store a password in plain text like that.

Visual basic 2010 vbulletin Loader

I am trying to create a vbulletin Loader for my site.
The main question is how to create a loader for vbulletin
The Loader works so it has permissions from vbulletin; if a user is a V.I.P., then he/she has access to inject a V.I.P .dll. A regular user can't inject that .dll, only limited to some not all and they cannot download the .dll. I am currently working on the login and its not working, nor that secure.
Module1.vb code;
Imports System.Security.Cryptography
Imports System.Text
Imports System.Net
Imports System
Imports System.IO
Module Module1
Public Function Login(ByVal Username As String, ByVal Password As String)
Password = MD5(Password)
Dim valid As Boolean = False
Dim data As String = "vb_login_username=" & Username & "&vb_login_password=&s=&do=login&vb_login_md5password=" & Password & "&vb_login_md5password_utf=" & Password
Try
Dim request As HttpWebRequest = WebRequest.Create("http://www.mywebsite.com/login.php?do=login")
request.Method = WebRequestMethods.Http.Post
request.ContentType = "application/x-www-form-urlencoded"
request.UserAgent = "-- vBulletin Vaidation --"
request.ContentLength = data.Length
Dim rStream As New StreamWriter(request.GetRequestStream)
rStream.Write(data)
rStream.Flush()
rStream.Close()
Dim response As HttpWebResponse = request.GetResponse
Dim resReader As New StreamReader(response.GetResponseStream)
Dim str As String = resReader.ReadToEnd
If str.Contains("Successful Login!") Then
valid = True
Else
valid = False
End If
response.Close()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error Failed to connect to www.mywebsite.com", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Return valid
End Function
Public Function MD5(ByVal number As String) As String
Dim ASCIIenc As New ASCIIEncoding
Dim strReturn As String = String.Empty
Dim ByteSourceText() As Byte = ASCIIenc.GetBytes(number)
Dim Md5Hash As New MD5CryptoServiceProvider
Dim ByteHash() As Byte = Md5Hash.ComputeHash(ByteSourceText)
For Each b As Byte In ByteHash
strReturn &= b.ToString("x2")
Next
Return strReturn
End Function
End Module
Form1 code;
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MsgBox("Copyright Notice: Copyright website 2013 - 2014 All Rights Reserved. - Click 'OK' to lunch Loader.")
End Sub
Private Sub CheckBox1_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles CheckBox1.CheckedChanged
If CheckBox1.Checked Then
My.Settings.mystring.Add(ComboBox1.Text)
ComboBox1.Items.Add(ComboBox1.Text)
My.Settings.Save()
End If
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If Login(ComboBox1.Text, TextBox1.Text) Then
MsgBox("Successfully Logged In!")
Me.Show()
Me.Close()
Else
MsgBox("Unknown Username and Password. Try Again.")
End If
End Sub

Read Text File and Output Multiple Lines to a Textbox

I'm trying to read a text file with multiple lines and then display it in a textbox. The problem is that my program only reads one line. Can someone point out the mistake to me?
Imports System.IO
Imports Microsoft.VisualBasic.FileIO
Public Class Form1
Private BagelStreamReader As StreamReader
Private PhoneStreamWriter As StreamWriter
Dim ResponseDialogResult As DialogResult
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
'Dim PhoneStreamWriter As New StreamWriter(OpenFileDialog1.FileName)
'Is file already open
If PhoneStreamWriter IsNot Nothing Then
PhoneStreamWriter.Close()
End If
With OpenFileDialog1
.InitialDirectory = Directory.GetCurrentDirectory
.FileName = OpenFileDialog1.FileName
.Title = "Select File"
ResponseDialogResult = .ShowDialog()
End With
'If ResponseDialogResult <> DialogResult.Cancel Then
' PhoneStreamWriter = New StreamWriter(OpenFileDialog1.FileName)
'End If
Try
BagelStreamReader = New StreamReader(OpenFileDialog1.FileName)
DisplayRecord()
Catch ex As Exception
MessageBox.Show("File not found or is invalid.", "Data Error")
End Try
End Sub
Private Sub DisplayRecord()
Do Until BagelStreamReader.Peek = -1
TextBox1.Text = BagelStreamReader.ReadLine()
Loop
'MessageBox.Show("No more records to display.", "End of File")
'End If
End Sub
Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
With SaveFileDialog1
.InitialDirectory = Directory.GetCurrentDirectory
.FileName = OpenFileDialog1.FileName
.Title = "Select File"
ResponseDialogResult = .ShowDialog()
End With
PhoneStreamWriter.WriteLine(TextBox1.Text)
With TextBox1
.Clear()
.Focus()
End With
TextBox1.Clear()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Dim PhoneStreamWriter As New StreamWriter(OpenFileDialog1.FileName)
PhoneStreamWriter.Close()
Me.Close()
End Sub
End Class
Here is a sample textfile:
Banana nut
Blueberry
Cinnamon
Egg
Plain
Poppy Seed
Pumpkin
Rye
Salt
Sesame seed
You're probably only getting the last line in the file, right? Your code sets TextBox1.Text equal to BagelSteramReader.ReadLine() every time, overwriting the previous value of TextBox1.Text. Try TextBox1.Text += BagelStreamReader.ReadLine() + '\n'
Edit: Though I must steal agree with Hans Passant's commented idea on this; If you want an more efficient algorithm, File.ReadAllLines() even saves you time and money...though I didn't know of it myself. Darn .NET, having so many features...
I wrote a program to both write to and read from a text file. To write the lines of a list box to a text file I used the following code:
Private Sub txtWriteToTextfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtWriteToTextfile.Click
Dim FileWriter As StreamWriter
FileWriter = New StreamWriter(FileName, False)
' 3. Write some sample data to the file.
For i = 1 To lstNamesList.Items.Count
FileWriter.Write(lstNamesList.Items(i - 1).ToString)
FileWriter.Write(Chr(32))
Next i
FileWriter.Close()
End Sub
And to read and write the contents of the text file and write to a multi-line text box (you just need to set the multiple lines property of a text box to true) I used the following code. I also had to do some extra coding to break the individual words from the long string I received from the text file.
Private Sub cmdReadFromTextfile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdReadFromTextfile.Click
Dim sStringFromFile As String = ""
Dim sTextString As String = ""
Dim iWordStartingPossition As Integer = 0
Dim iWordEndingPossition As Integer = 0
Dim iClearedTestLength As Integer = 0
Dim FileReader As StreamReader
FileReader = New StreamReader(FileName)
sStringFromFile = FileReader.ReadToEnd()
sTextString = sStringFromFile
txtTextFromFile.Text = ""
Do Until iClearedTestLength = Len(sTextString)
iWordEndingPossition = CInt(InStr((Microsoft.VisualBasic.Right(sTextString, Len(sTextString) - iWordStartingPossition)), " "))
txtTextFromFile.Text = txtTextFromFile.Text & (Microsoft.VisualBasic.Mid(sTextString, iWordStartingPossition + 1, iWordEndingPossition)) & vbCrLf
iWordStartingPossition = iWordStartingPossition + iWordEndingPossition
iClearedTestLength = iClearedTestLength + iWordEndingPossition
Loop
FileReader.Close()
End Sub