Enable Javascript


Last Arduino/ESP project (click to open)
Ster inactiefSter inactiefSter inactiefSter inactiefSter inactief
 

Artikelindex

modDiversen

modDiversen:
Wat hulpmiddelen voor algemeen gebruik.

Project NAW - modDiversen.vb


Imports System.Reflection
Imports System.IO
Imports System.Data.SQLite

Public Module Diversen
Public AppPath As String = ""
Public DbPath As String = ""
Public DbFile As String = ""
Public ConnectionString As String = ""
Public w1 As String = "" ' om wachtwoord in te verstoppen
Public w2 As String = GenerateStrongPW(32) ' om wachtwoord mee te verstoppen

' '' Voor GenerateStrongPW() en algemeen gebruik bij ingave-velden
Public Const Lettertekens As String = _
"~!@#$%^&*()_+[]{}<>?-=\,./:""| " & _
"abcdefghijklmnopqrstuvwxyz" & _
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" & _
"1234567890"

Public Function CompactDB() As Integer
' '' Compact/Compress/Vacuum 3 namen voor het zelfde doel: database opruimen
' '' Return: >=0 verschil in bytes, -1 = fout 
Try
Dim Connection As New SQLiteConnection
      Connection.ConnectionString = ConnectionString
Dim FileVoor, FileNa As Long
Dim Dir As New DirectoryInfo(DbPath)
Dim File As FileInfo() = Dir.GetFiles(DbFile)
      FileVoor = File(0).Length
Dim cmd As SQLiteCommand = Connection.CreateCommand()
      cmd.Connection.Open()
      cmd.CommandText = "VACUUM"
cmd.ExecuteNonQuery()
      cmd.Connection.Close()
      cmd.Dispose()
      File = Dir.GetFiles(DbFile)
      FileNa = File(0).Length
Return FileVoor - FileNa
Catch ex As Exception
Return -1
End Try
End Function

Public Function GetAppPath() As String
' '' Applicatie Path
' '' Kan anders maar werkt zo ook voor Mobile
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly()
Return System.IO.Path.GetDirectoryName(asm.GetName().CodeBase)
End Function

Public Function GenerateStrongPW(ByVal Lengte As Integer) As String
' '' Een sterk wachtwoord van 4-32 tekens aanmaken
Select Case Lengte
Case Is < 4 : Lengte = 4
Case Is > 32 : Lengte = 32
End Select
Dim StrongPW As String = ""
Dim symb1 As String = Lettertekens.Replace(" ", "").Replace(vbCrLf, "")
For i As Integer = 1 To Lengte
Dim rand As Random = New System.Random(Guid.NewGuid().GetHashCode())
Dim teken As Integer = rand.Next(0, symb1.Length - 1)
      StrongPW &= Lettertekens.Substring(teken, 1)
Next
Return StrongPW
End Function

Public Function w4(ByVal k As String) As String
' '' Wachtwoord en SubKey staan versleuteld in het geheugen 
' '' Bewust nietszeggende namen w1, w2, w3, w4 en k
Dim w3 As String = Decrypt(w1, w2) ' lees Wachtwoord 
Return Decrypt(k, w3) ' geef SubKey k
End Function

End Module