I am using the latest version of Awesomium for the WebControl for my application. When my application arrives at "accounts.google.com/ServiceLogin" it is supposed to execute some Javascript to have it automatically log in. In my.settings.java I have:
"document.getElementById('Email').value=""1"";document.getElementById('Passwd').value=""2"";document.getElementById('signIn').click()"
Value "1" being the email, and "2" being the password. So when the document is ready I have this:
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
I don't know why this is not working. When I paste the code directly in like this:
WebBrowser1.ExecuteJavascript("document.getElementById('Email').value=""1"";document.getElementById('Passwd').value=""2"";document.getElementById('signIn').click()")
The code works perfectly and it logs in. The reason I have it in my.settings is because I originally have it in a textbox, then I ask the user for their email and password, and then replace "1" with the email, and "2" with the password, then save the edited textbox text in my.settings.java. Then I have it look for the Javascript there instead of hard coding it into the application, and not being able to customize it for each user. Is any of my code wrong, or is there another way of doing this with Awesomium. Also, I am using the Awesomium WebControl1, I just changed it to WebBrowser1 because that is what I am used to typing. Sorry if this question is simple, as I am a student developer, with very limited knowledge in Javascript.
I never user my.settings when it comes to sensitive data like passwords (even emails). What I always do, I encrypt them in XML file using a simple yet dynamic encryption like this :
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
And it's still not that safe. The best way is to let the user put the password. As for your answer , if I understand you question, you need to create profiles, and store them in files/registry. (I recommend files or database). So that when "John" uses your program, he will select the "John" profile ... and so on.