VB 2013:从my.settings问题自动登录

时间:2014-07-09 02:25:18

标签: javascript .net vb.net awesomium

我正在为我的应用程序使用最新版本的Awesomium进行WebControl。当我的应用程序到达" accounts.google.com/ServiceLogin"它应该执行一些Javascript让它自动登录。在my.settings.java我有:

"document.getElementById('Email').value=""1"";document.getElementById('Passwd').value=""2"";document.getElementById('signIn').click()"

价值" 1"是电子邮件," 2"是密码。所以当文件准备就绪时,我有这个:

Private Sub WebBrowser1_DocumentReady(sender As Object, e As Awesomium.Core.UrlEventArgs) Handles WebBrowser1.DocumentReady
    If WebBrowser1.Source.ToString.Contains("accounts.google.com/ServiceLogin") = True Then
        WebBrowser1.ExecuteJavascript(My.Settings.java.ToString)
    Else

    End If

我不知道为什么这不起作用。当我直接粘贴代码时:

WebBrowser1.ExecuteJavascript("document.getElementById('Email').value=""1"";document.getElementById('Passwd').value=""2"";document.getElementById('signIn').click()")

代码完美运行并且登录。我在my.settings中拥有它的原因是因为我最初将它放在文本框中,然后我向用户询问他们的电子邮件和密码,然后替换" 1& #34;与电子邮件," 2"使用密码,然后将编辑的文本框文本保存在my.settings.java中。然后我让它在那里寻找Javascript而不是硬编码到应用程序中,并且无法为每个用户自定义它。我的任何代码是错误的,还是有其他方式使用Awesomium执行此操作。此外,我正在使用Awesomium WebControl1,我只是将其更改为WebBrowser1,因为这是我习惯打字。很抱歉,如果这个问题很简单,因为我是一名学生开发人员,对Javascript知之甚少。

1 个答案:

答案 0 :(得分:1)

在涉及密码(甚至电子邮件)等敏感数据时,我从不使用my.settings。我一直在做的事情,我使用简单但动态的加密方式在XML文件中加密它们,如下所示:


Public Function Encrypt(ByVal plainText As String) As String
    Dim passPhrase As String = **My.Computer.Name.ToString**
    Dim saltValue As String = **My.Computer.Info.OSFullName.ToString**
    Dim hashAlgorithm As String = "SHA1"
    Dim passwordIterations As Integer = 2
    Dim initVector As String = "@1B2c3D4e5F6g7H8"
    Dim keySize As Integer = 256
    Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
    Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
    Dim plainTextBytes As Byte() = Encoding.UTF8.GetBytes(plainText)
    Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)
    Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
    Dim symmetricKey As New RijndaelManaged()
    symmetricKey.Mode = CipherMode.CBC
    Dim encryptor As ICryptoTransform = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes)
    Dim memoryStream As New IO.MemoryStream()
    Dim cryptoStream As New CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write)
    cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length)
    cryptoStream.FlushFinalBlock()
    Dim cipherTextBytes As Byte() = memoryStream.ToArray()
    memoryStream.Close()
    cryptoStream.Close()
    Dim cipherText As String = Convert.ToBase64String(cipherTextBytes)
    Return cipherText
End Function

Public Function Decrypt(ByVal cipherText As String) As String
    Dim passPhrase As String = **My.Computer.Name.ToString**
    Dim saltValue As String = **My.Computer.Info.OSFullName.ToString**
    Dim hashAlgorithm As String = "SHA1"
    Dim passwordIterations As Integer = 2
    Dim initVector As String = "@1B2c3D4e5F6g7H8"
    Dim keySize As Integer = 256
    Dim initVectorBytes As Byte() = Encoding.ASCII.GetBytes(initVector)
    Dim saltValueBytes As Byte() = Encoding.ASCII.GetBytes(saltValue)
    Dim cipherTextBytes As Byte() = Convert.FromBase64String(cipherText)
    Dim password As New PasswordDeriveBytes(passPhrase, saltValueBytes, hashAlgorithm, passwordIterations)
    Dim keyBytes As Byte() = password.GetBytes(keySize \ 8)
    Dim symmetricKey As New RijndaelManaged()
    symmetricKey.Mode = CipherMode.CBC
    Dim decryptor As ICryptoTransform = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes)
    Dim memoryStream As New IO.MemoryStream(cipherTextBytes)
    Dim cryptoStream As New CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read)
    Dim plainTextBytes As Byte() = New Byte(cipherTextBytes.Length - 1) {}
    Dim decryptedByteCount As Integer = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length)
    memoryStream.Close()
    cryptoStream.Close()
    Dim plainText As String = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount)
    Return plainText
End Function

它仍然不那么安全。最好的方法是让用户输入密码。 至于你的答案,如果我理解你的问题,你需要创建配置文件,并将它们存储在文件/注册表中。 (我推荐文件或数据库)。因此,当“John”使用您的程序时,他将选择“John”配置文件......依此类推。