Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Password Protect  2.1 - Form1.vb

Form1.vb

Caricato da: Totem
Scarica il programma completo

  1. Imports spazio.GestioneFile
  2.  
  3. Public Class Form1
  4. #Region "Funzioni, procedure e variabili globali"
  5.     Public curdir As String = getpath(Application.ExecutablePath)
  6.     Public wps As String = curdir & "\wps.dat"
  7.     Public backup As String = curdir & "\Buffer.dat"
  8.     Public acapo As String = Chr(13) & Chr(10)
  9.     Public find_index As Int32 = -1
  10.     Public find_word As String
  11.     Public Sub Append(ByVal file As String, ByVal text As String)
  12.         Dim r As New System.IO.StreamReader(file)
  13.         Dim w As New System.IO.StreamWriter("001.dat")
  14.  
  15.         While Not r.EndOfStream
  16.             w.WriteLine(r.ReadLine)
  17.         End While
  18.  
  19.         r.Close()
  20.         r = Nothing
  21.         w.Write(text)
  22.         w.Close()
  23.         w = Nothing
  24.  
  25.         FileCopy("001.dat", file)
  26.         Kill("001.dat")
  27.     End Sub
  28.     Public Function Cripta(ByVal s As String) As String
  29.         Dim i As Int64
  30.         Dim cifra As Int16
  31.  
  32.         Cripta = ""
  33.  
  34.         For i = 0 To Len(s) - 1
  35.             cifra = Val(CType(i, String).Chars(CType(i, String).Length - 1))
  36.             If Asc(s.Chars(i)) + cifra < 255 Then
  37.                 Cripta = Cripta & Chr(Asc(s.Chars(i)) + cifra)
  38.             Else
  39.                 Cripta = Cripta & s.Chars(i)
  40.             End If
  41.         Next
  42.  
  43.         Return Cripta
  44.     End Function
  45.  
  46.     Public Function Decripta(ByVal s As String) As String
  47.         Dim i As Int64
  48.         Dim cifra As Int16
  49.  
  50.         Decripta = ""
  51.  
  52.         For i = 0 To Len(s) - 1
  53.             cifra = Val(CType(i, String).Chars(CType(i, String).Length - 1))
  54.             If Asc(s.Chars(i)) - cifra < 0 Then
  55.                 Decripta = Decripta & s.Chars(i)
  56.             Else
  57.                 Decripta = Decripta & Chr(Asc(s.Chars(i)) - cifra)
  58.             End If
  59.         Next
  60.  
  61.         Return Decripta
  62.     End Function
  63.     Public Function getpath(ByVal name As String) As String
  64.         Dim s As String = ""
  65.         Dim i, a As Int16
  66.  
  67.         For i = 0 To name.Length - 1
  68.             If name.Chars(i) = "\" Then
  69.                 a = i
  70.             End If
  71.         Next
  72.         For i = 0 To a
  73.             s = s & name.Chars(i)
  74.         Next
  75.  
  76.         Return s
  77.     End Function
  78.     Public Function Exists(ByVal s As String) As Boolean
  79.         Dim i As Int32
  80.  
  81.         For i = 0 To pass_list.Items.Count - 1
  82.             If Pos(s, pass_list.Items.Item(i)) > -1 Then
  83.                 Return True
  84.             End If
  85.         Next
  86.         Return False
  87.     End Function
  88.     Public Sub Refresh_list()
  89.         Dim r As New System.IO.StreamReader(wps)
  90.         Dim charge As String
  91.  
  92.         pass_list.Items.Clear()
  93.  
  94.         r.ReadLine()
  95.         While Not r.EndOfStream
  96.             charge = Decripta(r.ReadLine) & ", modificata il " & Decripta(r.ReadLine)
  97.             pass_list.Items.Add(charge)
  98.         End While
  99.         r.Close()
  100.         r = Nothing
  101.         s_label.Text = "Password inserite: " & pass_list.Items.Count
  102.     End Sub
  103.     Public Sub Refresh_status()
  104.         s_label.Text = "Password inserite: " & pass_list.Items.Count
  105.     End Sub
  106. #End Region
  107.  
  108.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  109.         Try
  110.             Dim r As New System.IO.StreamReader(wps)
  111.             Dim charge, inp As String
  112.  
  113.             charge = Decripta(r.ReadLine)
  114.  
  115.             inp = InputBox("Inserisci la Main Password per accedere a Password Protect 2.0: ", "Controllo password")
  116.             If inp <> charge Then
  117.                 MsgBox("Password errata!", MsgBoxStyle.Exclamation, "Errore #1")
  118.                 MsgBox(charge)
  119.                 r.Close()
  120.                 r = Nothing
  121.                 Application.Exit()
  122.                 Exit Sub
  123.             End If
  124.  
  125.             While Not r.EndOfStream
  126.                 charge = Decripta(r.ReadLine) & ", modificata il " & Decripta(r.ReadLine)
  127.                 pass_list.Items.Add(charge)
  128.             End While
  129.             r.Close()
  130.             r = Nothing
  131.             s_label.Text = "Password inserite: " & pass_list.Items.Count
  132.         Catch ex1 As System.IO.FileNotFoundException
  133.             Dim ris As Int16
  134.             ris = MsgBox("E' la prima volta che utilizzi Password Protect 2.0?", MsgBoxStyle.Question + MsgBoxStyle.YesNo, "Configurazione")
  135.             If ris = vbYes Then
  136.                 Dim p As String
  137.  
  138.                 p = InputBox("Inserisci la Main Password per accedere al programma:", "Immissione password")
  139.  
  140.                 Dim w As New System.IO.StreamWriter(wps)
  141.                 w.Write(Cripta(p))
  142.                 w.Close()
  143.                 w = Nothing
  144.                 FileCopy(wps, backup)
  145.             Else
  146.                 MsgBox("L'applicazione non riesce a trovare il componente wps.dat. Sessione terminata!", MsgBoxStyle.Critical, "Errore #2")
  147.             End If
  148.         End Try
  149.     End Sub
  150.  
  151.     Private Sub AggiungiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AggiungiToolStripMenuItem.Click
  152.         Dim use, pass As String
  153.  
  154.         use = InputBox("Inserire l'uso per cui la password è destinata:", "Uso della password", "[Esempio: Computer lavoro]")
  155.         If use = Nothing Then
  156.             MsgBox("Nessun impiego inserito!", MsgBoxStyle.Exclamation, "Errore #3")
  157.             Exit Sub
  158.         End If
  159.         If Exists(use) Then
  160.             MsgBox("Impiego già esistente!", MsgBoxStyle.Exclamation, "Errore #3")
  161.             Exit Sub
  162.         End If
  163.  
  164.         pass = InputBox("Inserire la password. Si può usufruire del generatore di password casuali fornito con il programma.", "Password")
  165.         If pass = Nothing Then
  166.             MsgBox("Nessuna password inserita!", MsgBoxStyle.Exclamation, "Errore #4")
  167.             Exit Sub
  168.         End If
  169.  
  170.         Dim comp, dat As String
  171.         Dim temp As New spazio.GestioneData
  172.  
  173.         comp = use & ": " & pass
  174.         dat = temp.giorno & "/" & temp.mese & "/" & temp.anno & "/" & " alle " & temp.ora & ":" & temp.minuti & ":" & temp.secondi
  175.  
  176.         Append(backup, Cripta(comp) & acapo & Cripta(dat))
  177.  
  178.         pass_list.Items.Add(comp & ", modificata il " & dat)
  179.         Refresh_status()
  180.  
  181.         FileCopy(backup, wps)
  182.     End Sub
  183.  
  184.     Private Sub RimuoviToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RimuoviToolStripMenuItem.Click
  185.         Dim ris As Int16
  186.  
  187.         If pass_list.SelectedIndex < 0 Then
  188.             MsgBox("Nessun elemento selezionato!", MsgBoxStyle.Exclamation, "Errore #5")
  189.             Exit Sub
  190.         End If
  191.  
  192.         ris = MsgBox("Si è sicuri di voler eliminare questa password?", MsgBoxStyle.Question + vbYesNo, "Conferma")
  193.  
  194.         If ris = vbYes Then
  195.             Dim r As New System.IO.StreamReader(wps)
  196.             Dim w As New System.IO.StreamWriter(backup)
  197.             Dim s As String
  198.  
  199.             While Not r.EndOfStream
  200.                 s = Decripta(r.ReadLine)
  201.                 If Pos(s, pass_list.SelectedItem) = 0 Then
  202.                     r.ReadLine()
  203.                 Else
  204.                     w.WriteLine(s)
  205.                 End If
  206.             End While
  207.  
  208.             r.Close()
  209.             w.Close()
  210.             r = Nothing
  211.             w = Nothing
  212.  
  213.             pass_list.Items.RemoveAt(pass_list.SelectedIndex)
  214.             Refresh_status()
  215.  
  216.             FileCopy(backup, wps)
  217.         End If
  218.     End Sub
  219.  
  220.     Private Sub ModificaToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModificaToolStripMenuItem.Click
  221.         Dim use, pass As String
  222.  
  223.         If pass_list.SelectedIndex < 0 Then
  224.             MsgBox("Nessun elemento selezionato!", MsgBoxStyle.Exclamation, "Errore #5")
  225.             Exit Sub
  226.         End If
  227.  
  228.         use = InputBox("Immettere il nuovo uso della password:", "Modifica uso")
  229.         If use = Nothing Then
  230.             MsgBox("Nessun impiego inserito!", MsgBoxStyle.Exclamation, "Errore #3")
  231.             Exit Sub
  232.         End If
  233.         If Exists(use) Then
  234.             MsgBox("Impiego già esistente!", MsgBoxStyle.Exclamation, "Errore #3")
  235.             Exit Sub
  236.         End If
  237.  
  238.         pass = InputBox("Inserire la nuova password. Si può usufruire del generatore di password casuali fornito con il programma.", "Modifica password")
  239.         If pass = Nothing Then
  240.             MsgBox("Nessuna password inserita!", MsgBoxStyle.Exclamation, "Errore #4")
  241.             Exit Sub
  242.         End If
  243.  
  244.         Dim r As New System.IO.StreamReader(wps)
  245.         Dim w As New System.IO.StreamWriter(backup)
  246.         Dim temp As New spazio.GestioneData
  247.         Dim s As String
  248.  
  249.         While Not r.EndOfStream
  250.             s = Decripta(r.ReadLine)
  251.             If Pos(s, pass_list.SelectedItem) = 0 Then
  252.                 r.ReadLine()
  253.                 w.WriteLine(Cripta(use & ": " & pass))
  254.                 w.WriteLine(Cripta(temp.giorno & "/" & temp.mese & "/" & temp.anno & "/" & " alle " & temp.ora & ":" & temp.minuti & ":" & temp.secondi))
  255.             Else
  256.                 w.WriteLine(Cripta(s))
  257.             End If
  258.         End While
  259.  
  260.         r.Close()
  261.         w.Close()
  262.         r = Nothing
  263.         w = Nothing
  264.  
  265.         FileCopy(backup, wps)
  266.  
  267.         Refresh_list()
  268.     End Sub
  269.  
  270.     Private Sub CambiaLaMainPasswordToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CambiaLaMainPasswordToolStripMenuItem.Click
  271.         Dim n_main As String
  272.  
  273.         n_main = InputBox("Nuova Main Password:", "Cambio Main Password")
  274.         If n_main = Nothing Then
  275.             MsgBox("Nessuna password inserita!", MsgBoxStyle.Exclamation, "Errore #4")
  276.             Exit Sub
  277.         End If
  278.  
  279.         Dim r As New System.IO.StreamReader(wps)
  280.         Dim w As New System.IO.StreamWriter(backup)
  281.         Dim s As String
  282.  
  283.         r.ReadLine()
  284.         w.WriteLine(Cripta(n_main))
  285.         While Not r.EndOfStream
  286.             s = r.ReadLine
  287.             w.WriteLine(s)
  288.         End While
  289.  
  290.         r.Close()
  291.         w.Close()
  292.         r = Nothing
  293.         w = Nothing
  294.  
  295.         FileCopy(backup, wps)
  296.  
  297.         MsgBox("Salvataggio avvenuto con successo!", MsgBoxStyle.Information, "Cambio Main Password")
  298.     End Sub
  299.  
  300.     Private Sub EsciToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EsciToolStripMenuItem.Click
  301.         FileCopy(backup, wps)
  302.         MsgBox("Salvataggio avvenuto con successo!", MsgBoxStyle.Information, "Cambio Main Password")
  303.     End Sub
  304.  
  305.     Private Sub EsciToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EsciToolStripMenuItem1.Click
  306.         FileCopy(backup, wps)
  307.         Me.Close()
  308.     End Sub
  309.  
  310.     Private Sub EliminaTuttoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminaTuttoToolStripMenuItem.Click
  311.         Dim ris As Int16
  312.  
  313.         ris = MsgBox("Sei sicuro di voler eliminare tutte le password fin'ora memorizzate?", MsgBoxStyle.Question + vbYesNo, "Eliminazione di massa")
  314.         If ris = vbYes Then
  315.             Dim r As New System.IO.StreamReader(wps)
  316.             Dim w As New System.IO.StreamWriter(backup)
  317.  
  318.             w.WriteLine(r.ReadLine)
  319.  
  320.             r.Close()
  321.             w.Close()
  322.             r = Nothing
  323.             w = Nothing
  324.  
  325.             FileCopy(backup, wps)
  326.  
  327.             pass_list.Items.Clear()
  328.  
  329.             Refresh_status()
  330.         End If
  331.     End Sub
  332.  
  333.     Private Sub EliminaSelezionatiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EliminaSelezionatiToolStripMenuItem.Click
  334.         find_index = 0
  335.         find_word = InputBox("Immettere la stringa per cui cercare:", "Ricerca")
  336.         If find_word = Nothing Then
  337.             MsgBox("Nessuna stringa inserita!", MsgBoxStyle.Exclamation, "Errore #4")
  338.             Exit Sub
  339.         End If
  340.  
  341.         Dim i As Int32
  342.         For i = 0 To pass_list.Items.Count - 1
  343.             If Pos(find_word, pass_list.Items.Item(i)) > -1 Then
  344.                 find_index = i
  345.                 pass_list.SelectedIndex = i
  346.                 Exit For
  347.             End If
  348.         Next
  349.     End Sub
  350.  
  351.     Private Sub AboutPasswordProtect20ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutPasswordProtect20ToolStripMenuItem.Click
  352.         Dim f As New Password_Manager_2.About
  353.         f.Show()
  354.     End Sub
  355.  
  356.     Private Sub GeneratoreDiPasswordCasualiToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GeneratoreDiPasswordCasualiToolStripMenuItem.Click
  357.         Dim f As New Password_Manager_2.Form2
  358.         f.Show()
  359.     End Sub
  360. End Class