Could someone help me with my login system by adding password masking system [duplicate] - vb.net

This question already has an answer here:
How can I interpret a masking system in my login system?
(1 answer)
Closed 8 years ago.
I can't find a way round in adding a code which doesn't treat the backspace button as a character. It would be great if someone could implement a few lines of code in order to make it possible for the program to delete letters, whilst not perceiving the backspace button as a letter.
Dim fullline As String = ""
FileOpen(1, "E:\Computing\Spelling Bee\StaffPasswords\staffpassword.csv", OpenMode.Input)
fullline = LineInput(1)
Dim item() As String = Split(fullline, ",")
Dim info As ConsoleKeyInfo
Console.Write("Password: ")
Dim enteredpassword As String = ""
Dim password As String = fullline
Do
info = Console.ReadKey(True)
If info.Key = ConsoleKey.Enter Then
Exit Do
Else
enteredpassword &= info.KeyChar
Console.Write("*"c)
End If
If enteredpassword = password And ConsoleKey.Enter Then
Console.WriteLine()
Console.WriteLine("Works")
End If
Loop
Console.WriteLine()
Console.ReadKey()

Dim item() As String
Using rdr As New TextFieldParser("E:\Computing\Spelling Bee\StaffPasswords\staffpassword.csv")
rdr.TextFieldType = FieldType.Delimited
rdr.Delimiters = New String() {","c}
item = rdr.ReadFields()
End Using
Console.Write("Password: ")
Dim enteredpassword As String
Dim password As String = item(0)
Dim info As ConsoleKeyInfo
Do
info = Console.ReadKey(True)
If info.Key = ConsoleKey.Enter Then Exit Do
If info.Key = ConsoleKey.BackSpace AndAlso enteredpassword.Length > 0 Then
enteredpassword = enteredpassword.SubString(0, enteredpassword.Length -1)
Console.Write(vbBack)
Else
enteredpassword &= info.KeyChar
Console.Write("*"c)
End If
Loop
If enteredpassword = password Then
Console.WriteLine()
Console.WriteLine("Works")
End If
Console.WriteLine()
Console.ReadKey(True)

Related

“Input string was not in a correct format” while parsing the content of a file

I need help, I don't know why the array for the quantity in my input file strArr(1) having an error that says that the input string was not in a correct format.
Dim objReader As IO.StreamReader
Dim objWriter As New IO.StreamWriter("C:\Users\user\Desktop\StationeryFolder\output.txt")
Dim strLine As String
Dim strName As String
Dim intQuantity As Integer
Dim intTotal As Integer
Dim strArr() As String
If IO.File.Exists("C:\Users\user\Desktop\StationeryFolder\input.txt") = True Then
objReader = IO.File.OpenText("C:\Users\user\Desktop\StationeryFolder\input.txt")
Else
MsgBox("File is not exist")
Close()
End If
Do While objReader.Peek <> -1
strLine = objReader.ReadLine()
strArr = strLine.Split(" ")
strName = strArr(0)
intQuantity = Convert.ToInt32(strArr(1)) //this is where the error occurs
intTotal = intTotal + intQuantity
lstDisplay.Items.Add(strName & " " & intQuantity.ToString())
objWriter.WriteLine(strName & " " & intQuantity.ToString())
Loop
lstDisplay.Items.Add("Total Quantity of Stationeries are: " & intTotal.ToString())
objWriter.WriteLine("Total Quantity of Stationeries are: " & intTotal.ToString())
objReader.Close()
objWriter.Close()
Inside the input file:
Markers
15
Pens
25
I used the .net File class instead of streams. ReadAllLine returns an array of the lines in the file. I used a StringBuilder which is mutable (changeable) unlike a String. Saves the code from creating and throwing away several strings. I have used interpolated strings indicated by the $ before the quotes. This allows inserting variables directly into the string surrounded by braces.
Private Sub OPCode()
Dim inputPath = "C:\Users\user\Desktop\StationeryFolder\input.txt"
If Not IO.File.Exists(inputPath) Then
MsgBox("File does not exist")
Close()
End If
Dim lines = File.ReadAllLines(inputPath)
Dim total As Integer
Dim sb As New StringBuilder
For i = 0 To lines.Length - 2 Step 2
lstDisplay.Items.Add($"{lines(i)} {lines(i + 1)}")
sb.AppendLine($"{lines(i)} {lines(i + 1)}")
total += CInt(lines(i + 1))
Next
lstDisplay.Items.Add($"Total Quantity of Stationeries are: {total}")
sb.AppendLine($"Total Quantity of Stationeries are: {total}")
File.WriteAllText("C:\Users\user\Desktop\StationeryFolder\output.txt", sb.ToString)
End Sub

How to read from a file and search for the input of the user on the file? VB.NET

This my code i want to search for the input of the user i.e string on a certain .txt file and if it finds it displays date found else input not found.
Dim freader As IO.StreamReader
Dim strline, a As String
freader = New IO.StreamReader(" C:\Users\neWbie889\Documents\vb\strings.txt")
strline = freader.ReadLine
Do While Not strline Is Nothing
strline = freader.ReadLine()
Loop
Console.WriteLine("enter your string")
a = Console.ReadLine()
If strline = a Then
Console.WriteLine("input found")
ElseIf strline <> a Then
Console.WriteLine("input not found")
End If
freader.Close()
the text file consists of data in this order:
750401 234523
456465 345345
054156 34534
023156 534543
156456 435345
You can read all the text from the file into a string:
Dim allText As String = File.ReadAllText("path to file")
and then check for the string the user gave with Contains method:
If allText.Contains(a) = True Then
Console.WriteLine("input found")
Else
Console.WriteLine("input not found")
End If
Imports System.IO
Module Module1
Sub Main()
Dim a As String
Dim allText As String = File.ReadAllText("C:\Users\KronosXtitan\Documents\vb\ddates.txt")
Console.WriteLine("enter a number")
a = Console.ReadLine()
If allText.Contains(a) = True Then
Console.WriteLine("the number was found")
Else
Console.WriteLine("the number was not found")
End If
End Sub
End Module
thanks to γηράσκω δ' αεί πολλά διδασκόμε for helping me solve this

Visual Basic: i have a file containg usernames and passwords but i want to read them back in so the user can log back in

Do
Do
Console.WriteLine("Create a password. It must be 8 characters in length")
password1 = Console.ReadLine()
Loop Until password1.Length = 8
Console.WriteLine("Please re-enter the password.")
password2 = Console.ReadLine()
Loop Until password2 = password1
password = password1
Console.WriteLine("your password has been created.")
Console.ReadLine()
The below code generates the file
Dim fileName = "C:\Users\emily\Documents\Details.csv"
Dim fileAppend As New System.IO.StreamWriter(fileName, True)
fileAppend.WriteLine(name & ", " & age & ", " & username & ", " & password & ", " & yeargroup)
fileAppend.Close()
So basically I have details about the users stored in a csv file. The columns are arranged as follows: name, age, username, password, yeargroup. I need to be able to input a username and for it to be found in the array/list and then input the password and if the password doesn't match for it to start again.
Nice homework. You should think about storing password. Clear text is obviously risky. With the user file load in a table like this will let you manage all of the user. Add,Remove, Change then just save over the userfile.
Public Class Form1
Dim UserTable As New DataTable("UserTable")
Dim SomeUserName As String = "slims"
Dim SomePassword As String = "abc1234!"
Sub ReadUserFile()
Dim fileName = "C:\dump\test.csv"
Dim fileReader As New System.IO.StreamReader(fileName)
UserTable.Columns.Add("Name")
UserTable.Columns.Add("Age")
UserTable.Columns.Add("Username")
UserTable.Columns.Add("Password")
UserTable.Columns.Add("YearGroup")
Do Until fileReader.EndOfStream = True
Dim OneLine As String = fileReader.ReadLine()
UserTable.Rows.Add(OneLine.Split(","))
Loop
fileReader.Close()
End Sub
Sub WriteUserFile()
Dim fileName = "C:\dump\test.csv"
Dim fileWriter As New System.IO.StreamWriter(fileName)
For Each xRow As DataRow In UserTable.Rows
fileWriter.WriteLine(String.Format("{0},{1},{2},{3},{4}", xRow("Name"), xRow("Age"), xRow("Username"), xRow("Password"), xRow("YearGroup")))
Next
fileWriter.Close()
End Sub
Function CheckUserPassword(UserName As String, Password As String) As Boolean
Dim Found As Boolean = False
For Each xRow As DataRow In UserTable.Rows
If (xRow("Username") = SomeUserName) And (xRow("Password") = SomePassword) Then
Found = True
Exit For
Else
Found = False
End If
Next
Return Found
End Function
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ReadUserFile()
If CheckUserPassword(SomeUserName, SomePassword) = True Then
'Good to go
Else
'bad user/pass
End If
WriteUserFile()
End Sub
End Class
You can use IO.File.ReadAllLines(fileName) to read the lines into an array of strings. Then you can use String.Split() on each line to split the fields and pick out the username and password.
dim allLines as String() = IO.File.ReadAllLines(fileName)
for each line as String in allLines
dim lineArray() as string
lineArray = line.Split(New Char() {","c})
username = lineArray(2)
password = lineArray(3)
if username = theUsernameYouWant then
'Found the user. Now check their password
endif
next
I havn't tested this code. Might have syntax errors.

Loop through the lines of a text file in VB.NET

I have a text file with some lines of text in it.
I want to loop through each line until an item that I want is found*, then display it on the screen, in the form of a label.
*I am searching for the item through a textbox.
That is, in sudo:
For i = 0 To number of lines in text file
If txtsearch.text = row(i).text Then
lbl1.text = row(i).text
Next i
You can use the File.ReadLines Method in order to iterate throughout your file, one line at a time. Here is a simple example:
Dim Term As String = "Your term"
For Each Line As String In File.ReadLines("Your file path")
If Line.Contains(Term) = True Then
' Do something...Print the line
Exit For
End If
Next
Here's a function that will spit back your string from the row that contains your search term...
Public Shared Function SearchFile(ByVal strFilePath As String, ByVal strSearchTerm As String) As String
Dim sr As StreamReader = New StreamReader(strFilePath)
Dim strLine As String = String.Empty
Try
Do While sr.Peek() >= 0
strLine = String.Empty
strLine = sr.ReadLine
If strLine.Contains(strSearchTerm) Then
sr.Close()
Exit Do
End If
Loop
Return strLine
Catch ex As Exception
Return String.Empty
End Try
End Function
To use the function you can do this...
Dim strText As String = SearchFile(FileName, SearchTerm)
If strText <> String.Empty Then
Label1.Text = strText
End If
LOOPING AND GETTING ALL XML FILES FROM DIRECTORY IF WE WANT TEXTFILES PUT "*.txt" IN THE PLACE OF "*xml"
Dim Directory As New IO.DirectoryInfo(Path)
Dim allFiles As IO.FileInfo() = Directory.GetFiles("*.xml")
allFiles = allFiles.OrderByDescending(Function(x) x.FullName).ToArray()
Dim singleFile As IO.FileInfo
For Each singleFile In allFiles
'ds.ReadXml(singleFile)
xd.Load(singleFile.FullName)
Dim nodes As XmlNodeList = xd.DocumentElement.SelectNodes("/ORDER/ORDER_HEADER")
Dim ORDER_NO As String = " "
For Each node As XmlNode In nodes
If Not node.SelectSingleNode("ORDER_NO") Is Nothing Then
ORDER_NO = node.SelectSingleNode("ORDER_NO").InnerText
End If
Next
Next

Grabbing values sent to a console application in VB.net

What I'm trying to accomplish I have a textbox control and a button control on a form. When clicked whatever is entered into the textbox control, I want to send that data to a console application, which in turn create a text file. I have it mostly working but I can't get the data sent from the web application. How do I accomplish this? Here is what I have so far.
Here is my sub to send to the console application:
Public Sub send_to_console()
Dim file As String = "C:\inetpub\wwwroot\TestConsoleApp\TestConsoleApp\bin\Debug\TestConsoleApp.exe"
Dim info As ProcessStartInfo = New ProcessStartInfo(file, TextBox1.Text)
Dim p As Process = Process.Start(info)
End Sub
Console App Code:
ublic Sub Main(ByVal args As String)
Dim w As StreamWriter
Dim filepath As String = "C:\xml_files\testFile.txt"
Dim new_string As String
new_string = "This has been completed on " & Date.Now
If args = "" Then
new_string = "No data entered on: " & Date.Now
Else
new_string = args & " " & Date.Now
End If
If System.IO.File.Exists(filepath) Then
File.Delete(filepath)
End If
w = File.CreateText(filepath)
w.WriteLine(new_string)
w.Flush()
w.Close()
End Sub
Currently i'm getting an error: no accessible Main
'#######################EDITS###########
Dim file As String = "C:\inetpub\wwwroot\TestConsoleApp\TestConsoleApp\bin\Debug\TestConsoleApp.exe"
Dim info As ProcessStartInfo = New ProcessStartInfo(file, TextBox1.Text)
info.UseShellExecute = False
Dim p As Process = Process.Start(info)
main takes an array of string not a string.
so
Public Sub Main(ByVal args As String())
.....
If args.length < 1 Then
new_string = "No data entered on: " & Date.Now
Else
new_string = args(0) & " " & Date.Now
End If
.....
End Sub
In order to prevent windows from splitting your arguments concatenate a quote character before and after
Dim info As ProcessStartInfo = New ProcessStartInfo(file, """" & TextBox1.Text & """")
Four double quote characters represent a string literal containing a single double quote.