VB 2013:自动登录从我的.设置问题

VB 2013: Auto login from my.settings issue

本文关键字:我的 设置 问题 登录 2013 VB      更新时间:2023-09-26

我的应用程序使用的是最新版本的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()")

代码工作完美,它登录。我把它放在我的。设置是因为我最初将其放在一个文本框中,然后我向用户询问他们的电子邮件和密码,然后将"1"替换为电子邮件,将"2"替换为密码,然后将编辑后的文本框文本保存在my.settings.java中。然后我让它在那里寻找Javascript,而不是将其硬编码到应用程序中,并且无法为每个用户定制它。是我的任何代码错误,或者有另一种方式做到这一点与Awesomium。此外,我正在使用Awesomium WebControl1,我只是将其更改为WebBrowser1,因为这是我习惯键入的。对不起,如果这个问题很简单,因为我是一名学生开发人员,在Javascript知识非常有限。

我从不使用我的。设置敏感数据,如密码(甚至电子邮件)。我通常的做法是,将它们加密到XML文件中使用简单的动态加密,如下所示:

<>之前Public Function Encrypt(ByVal明文As String) As StringDim passPhrase As String = **My.Computer.Name.ToString**Dim saltValue As String = **My.Computer.Info.OSFullName.ToString**Dim hashhalgalgorithm As String = "SHA1"Dim passwordIterations As Integer = 2Dim initVector As String = "@1B2c3D4e5F6g7H8"Dim keySize As Integer = 256Dim 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(passsphrase, saltValueBytes, hashalgalgorithm, passwordIterations)Dim keyBytes As Byte() = password。GetBytes(keySize ' 8)Dim symmetricKey As New RijndaelManaged()symmetricKey。Mode = CipherMode。加拿大广播公司暗淡加密器如ICryptoTransform = symmetricKey。CreateEncryptor (keyBytes initVectorBytes)Dim memoryStream As New IO.MemoryStream()Dim cryptoStream As New cryptoStream (memoryStream, encryptor, cryptoStream mode . 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)返回密文结束函数Decrypt(ByVal cipherText As String) As StringDim passPhrase As String = **My.Computer.Name.ToString**Dim saltValue As String = **My.Computer.Info.OSFullName.ToString**Dim hashhalgalgorithm As String = "SHA1"Dim passwordIterations As Integer = 2Dim initVector As String = "@1B2c3D4e5F6g7H8"Dim keySize As Integer = 256Dim 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(passsphrase, saltValueBytes, hashalgalgorithm, passwordIterations)Dim keyBytes As Byte() = password。GetBytes(keySize ' 8)Dim symmetricKey As New RijndaelManaged()symmetricKey。Mode = CipherMode。加拿大广播公司Dim decryptor为ICryptoTransform = symmetricKey。者keyBytes initVectorBytes)Dim memoryStream As New IO.MemoryStream(cipherTextBytes)Dim cryptoStream As New cryptoStream (memoryStream, decryptor, cryptoStream mode . read)Dim plainTextBytes As Byte() = New Byte(cipherTextBytes.)长度- 1){}Dim decryptedByteCount As Integer = cryptoStream。读取(plainTextBytes, 0, plainTextBytes. length)memoryStream.Close ()cryptoStream.Close ()暗淡明文作为字符串= Encoding.UTF8。GetString(plainTextBytes, 0, decryptedByteCount)返回明文结束函数之前

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