Imports spazio.GestioneFile
Public Class Form1
#Region "Funzioni, procedure e variabili globali"
Public curdir As String = getpath(Application.ExecutablePath)
Public wps As String = curdir & "\wps.dat"
Public backup As String = curdir & "\Buffer.dat"
Public acapo As String = Chr(13) & Chr(10)
Public find_index As Int32 = -1
Public find_word As String
Public Sub Append
(ByVal file As String,
ByVal text
As String)
Dim r
As New System.
IO.
StreamReader(file)
Dim w As New System.IO.StreamWriter("001.dat")
While Not r.EndOfStream
w.WriteLine(r.ReadLine)
End While
r.Close()
r = Nothing
w.Write(text)
w.Close()
w = Nothing
FileCopy("001.dat",
file)
Kill("001.dat")
End Sub
Public Function Cripta(ByVal s As String) As String
Dim i As Int64
Dim cifra As Int16
Cripta = ""
For i = 0 To Len(s) - 1
cifra = Val(CType(i, String).Chars(CType(i, String).Length - 1))
If Asc(s.Chars(i)) + cifra < 255 Then
Cripta = Cripta & Chr(Asc(s.Chars(i)) + cifra)
Else
Cripta = Cripta & s.Chars(i)
End If
Next
Return Cripta
End Function
Public Function Decripta(ByVal s As String) As String
Dim i As Int64
Dim cifra As Int16
Decripta = ""
For i = 0 To Len(s) - 1
cifra = Val(CType(i, String).Chars(CType(i, String).Length - 1))
If Asc(s.Chars(i)) - cifra < 0 Then
Decripta = Decripta & s.Chars(i)
Else
Decripta = Decripta & Chr(Asc(s.Chars(i)) - cifra)
End If
Next
Return Decripta
End Function
Public Function getpath(ByVal name As String) As String
Dim s As String = ""
Dim i, a As Int16
For i = 0 To name.Length - 1
If name.Chars(i) = "\" Then
a = i
End If
Next
For i = 0 To a
s = s & name.Chars(i)
Next
Return s
End Function
Public Function Exists(ByVal s As String) As Boolean
Dim i As Int32
For i = 0 To pass_list.Items.Count - 1
If Pos(s, pass_list.Items.Item(i)) > -1 Then
Return True
End If
Next
Return False
End Function
Public Sub Refresh_list()
Dim r As New System.IO.StreamReader(wps)
Dim charge As String
pass_list.Items.Clear()
r.ReadLine()
While Not r.EndOfStream
charge = Decripta(r.ReadLine) & ", modificata il " & Decripta(r.ReadLine)
pass_list.Items.Add(charge)
End While
r.Close()
r = Nothing
s_label.Text = "Password inserite: " & pass_list.Items.Count
End Sub
Public Sub Refresh_status()
s_label.Text = "Password inserite: " & pass_list.Items.Count
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Try
Dim r As New System.IO.StreamReader(wps)
Dim charge, inp As String
charge = Decripta(r.ReadLine)
inp = InputBox("Inserisci la Main Password per accedere a Password Protect 2.0: ", "Controllo password")
If inp <> charge Then
MsgBox("Password errata!", MsgBoxStyle.Exclamation, "Errore #1")
MsgBox(charge)
r.Close()
r = Nothing
Application.Exit()
Exit Sub
End If
While Not r.EndOfStream
charge = Decripta(r.ReadLine) & ", modificata il " & Decripta(r.ReadLine)
pass_list.Items.Add(charge)
End While
r.Close()
r = Nothing
s_label.Text = "Password inserite: " & pass_list.Items.Count
Catch ex1 As System.IO.FileNotFoundException
Dim ris As Int16
ris = MsgBox("E' la prima volta che utilizzi Password Protect 2.0?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Configurazione")
If ris = vbYes Then
Dim p As String
p = InputBox("Inserisci la Main Password per accedere al programma:", "Immissione password")
Dim w As New System.IO.StreamWriter(wps)
w.Write(Cripta(p))
w.Close()
w = Nothing
FileCopy(wps, backup)
Else
MsgBox("L'applicazione non riesce a trovare il componente wps.dat. Sessione terminata!", MsgBoxStyle.Critical, "Errore #2")
End If
End Try
End Sub
Private Sub AggiungiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AggiungiToolStripMenuItem.Click
Dim use, pass As String
use = InputBox("Inserire l'uso per cui la password è destinata:", "Uso della password", "[Esempio: Computer lavoro]")
If use = Nothing Then
MsgBox("Nessun impiego inserito!", MsgBoxStyle.Exclamation, "Errore #3")
Exit Sub
End If
If Exists(use) Then
MsgBox("Impiego già esistente!", MsgBoxStyle.Exclamation, "Errore #3")
Exit Sub
End If
pass = InputBox("Inserire la password. Si può usufruire del generatore di password casuali fornito con il programma.", "Password")
If pass = Nothing Then
MsgBox("Nessuna password inserita!", MsgBoxStyle.Exclamation, "Errore #4")
Exit Sub
End If
Dim comp, dat As String
Dim temp As New spazio.GestioneData
comp = use & ": " & pass
dat = temp.giorno & "/" & temp.mese & "/" & temp.anno & "/" & " alle " & temp.ora & ":" & temp.minuti & ":" & temp.secondi
Append(backup, Cripta(comp) & acapo & Cripta(dat))
pass_list.Items.Add(comp & ", modificata il " & dat)
Refresh_status()
FileCopy(backup, wps)
End Sub
Private Sub RimuoviToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RimuoviToolStripMenuItem.Click
Dim ris As Int16
If pass_list.SelectedIndex < 0 Then
MsgBox("Nessun elemento selezionato!", MsgBoxStyle.Exclamation, "Errore #5")
Exit Sub
End If
ris = MsgBox("Si è sicuri di voler eliminare questa password?", MsgBoxStyle.Question + vbYesNo, "Conferma")
If ris = vbYes Then
Dim r As New System.IO.StreamReader(wps)
Dim w As New System.IO.StreamWriter(backup)
Dim s As String
While Not r.EndOfStream
s = Decripta(r.ReadLine)
If Pos(s, pass_list.SelectedItem) = 0 Then
r.ReadLine()
Else
w.WriteLine(s)
End If
End While
r.Close()
w.Close()
r = Nothing
w = Nothing
pass_list.Items.RemoveAt(pass_list.SelectedIndex)
Refresh_status()
FileCopy(backup, wps)
End If
End Sub
Private Sub ModificaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModificaToolStripMenuItem.Click
Dim use, pass As String
If pass_list.SelectedIndex < 0 Then
MsgBox("Nessun elemento selezionato!", MsgBoxStyle.Exclamation, "Errore #5")
Exit Sub
End If
use = InputBox("Immettere il nuovo uso della password:", "Modifica uso")
If use = Nothing Then
MsgBox("Nessun impiego inserito!", MsgBoxStyle.Exclamation, "Errore #3")
Exit Sub
End If
If Exists(use) Then
MsgBox("Impiego già esistente!", MsgBoxStyle.Exclamation, "Errore #3")
Exit Sub
End If
pass = InputBox("Inserire la nuova password. Si può usufruire del generatore di password casuali fornito con il programma.", "Modifica password")
If pass = Nothing Then
MsgBox("Nessuna password inserita!", MsgBoxStyle.Exclamation, "Errore #4")
Exit Sub
End If
Dim r As New System.IO.StreamReader(wps)
Dim w As New System.IO.StreamWriter(backup)
Dim temp As New spazio.GestioneData
Dim s As String
While Not r.EndOfStream
s = Decripta(r.ReadLine)
If Pos(s, pass_list.SelectedItem) = 0 Then
r.ReadLine()
w.WriteLine(Cripta(use & ": " & pass))
w.WriteLine(Cripta(temp.giorno & "/" & temp.mese & "/" & temp.anno & "/" & " alle " & temp.ora & ":" & temp.minuti & ":" & temp.secondi))
Else
w.WriteLine(Cripta(s))
End If
End While
r.Close()
w.Close()
r = Nothing
w = Nothing
FileCopy(backup, wps)
Refresh_list()
End Sub
Private Sub CambiaLaMainPasswordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CambiaLaMainPasswordToolStripMenuItem.Click
Dim n_main As String
n_main = InputBox("Nuova Main Password:", "Cambio Main Password")
If n_main = Nothing Then
MsgBox("Nessuna password inserita!", MsgBoxStyle.Exclamation, "Errore #4")
Exit Sub
End If
Dim r As New System.IO.StreamReader(wps)
Dim w As New System.IO.StreamWriter(backup)
Dim s As String
r.ReadLine()
w.WriteLine(Cripta(n_main))
While Not r.EndOfStream
s = r.ReadLine
w.WriteLine(s)
End While
r.Close()
w.Close()
r = Nothing
w = Nothing
FileCopy(backup, wps)
MsgBox("Salvataggio avvenuto con successo!", MsgBoxStyle.Information, "Cambio Main Password")
End Sub
Private Sub EsciToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EsciToolStripMenuItem.Click
FileCopy(backup, wps)
MsgBox("Salvataggio avvenuto con successo!", MsgBoxStyle.Information, "Cambio Main Password")
End Sub
Private Sub EsciToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EsciToolStripMenuItem1.Click
FileCopy(backup, wps)
Me.Close()
End Sub
Private Sub EliminaTuttoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminaTuttoToolStripMenuItem.Click
Dim ris As Int16
ris = MsgBox("Sei sicuro di voler eliminare tutte le password fin'ora memorizzate?", MsgBoxStyle.Question + vbYesNo, "Eliminazione di massa")
If ris = vbYes Then
Dim r As New System.IO.StreamReader(wps)
Dim w As New System.IO.StreamWriter(backup)
w.WriteLine(r.ReadLine)
r.Close()
w.Close()
r = Nothing
w = Nothing
FileCopy(backup, wps)
pass_list.Items.Clear()
Refresh_status()
End If
End Sub
Private Sub EliminaSelezionatiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminaSelezionatiToolStripMenuItem.Click
find_index = 0
find_word = InputBox("Immettere la stringa per cui cercare:", "Ricerca")
If find_word = Nothing Then
MsgBox("Nessuna stringa inserita!", MsgBoxStyle.Exclamation, "Errore #4")
Exit Sub
End If
Dim i As Int32
For i = 0 To pass_list.Items.Count - 1
If Pos(find_word, pass_list.Items.Item(i)) > -1 Then
find_index = i
pass_list.SelectedIndex = i
Exit For
End If
Next
End Sub
Private Sub AboutPasswordProtect20ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutPasswordProtect20ToolStripMenuItem.Click
Dim f As New Password_Manager_2.About
f.Show()
End Sub
Private Sub GeneratoreDiPasswordCasualiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GeneratoreDiPasswordCasualiToolStripMenuItem.Click
Dim f As New Password_Manager_2.Form2
f.Show()
End Sub
End Class