<%# language = "VBScript"%>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="">
Username:<br> <input type = "text" name = "user"/><br>
Password:<br> <input type = "password" name = "pass"/><br>
<input type = "submit" name = "register_button" value = "Register"/>
<input type = "submit" name = "submit_button" value = "Submit"/>
</form>
<%
set credentials = Server.CreateObject("Scripting.Dictionary")
set Session("credentials") = credentials
if Request.form("register_button") <> "" then
dim user
dim pass
pass = Request.form("pass")
user = Request.form("user")
Session("credentials").Add user, pass
end if
if Request.form("submit_button") <> "" then
dim userd
dim passd
passd = Request.form("pass")
userd = Request.form("user")
if Session("credentials").Exists(userd) = true then
if Session("credentials").Item(userd) = passd then
Response.Write("ACCESS GRANTED")
else
Response.Write("ACCESS DENIED")
end if
else
Response.Write("USERNAME DOES NOT EXIST")
end if
end if
%>
</body>
</html>
So this is a basic login page I created using Classic ASP. When I type in a user and pass, then click Register, it stores the username and password in the Dictionary no problem. But, when I click the submit button (after filling in the registered credentials), somehow the contents of the dictionary get deleted. So, it fails the "if Session("credentials").Exists(userd) = true then" statement. I even tried making "credentials" a normal variable, without using Session. It still won't work, the dictionary's contents just get deleted. How can I overcome this problem? Thanks in advance!
this first
credentials.Add user, pass
set Session("credentials") = credentials
should be after
Related
I am having an issue with one part of my automation job, and that is selecting ALL the options in a combobox, on a webpage, using VBA and IE.
This code selects ONE item in the combo box
Set frm = HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
frm.Value = "AUT"
However, when I try to select multiple items, it just selects the last one, not all of them.
Here is the code from the web page
<p id="DispFormCollapsible.Rc10"class="formrow" >
<span id="DispFormCollapsible.Rc10.C1" class="querytextleft">
<label for="UFG.USER_TYPES" id="LabelForContro123"class = "simpletext" >
Accessible Types:<span class="redstar">*</span></label></span>
<span id="DispFormCollapsible.Rc10.C2" class="querytextright">
<span class="labelColumn_combo">
<span class="labelColumn_combi_brdr">
<select name= "UFG.USER_TYPES" multiple= "true" class = "dropdownexpandalbe"
id="UFG.USER_TYPES" title = "Accessible Financial Transaction Types">
<option value="AUT" title="ACTIVE USER TYPE1" >TYPE1</option>
<option value="SET" title="Selective User Type" >TYPE2</option>
<option value="TST" title="Test User Type" >TEST3</option>
</select></span></span>
<input type ="hidden" name= "UFG.USER_TYPES" value="NULL" >
</span></p>
Here is my VBA line to select an item
Set frm = HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
frm.Value = "AUT"
What I need it to do, is select all the "option values" in the combobox. I think it needs to be an array maybe, or some other way. I've tried searching, but I'm getting nowhere. Any help appreciated. Thx
Tried the following, but get an error 91 Block not set. I've also tried using the Values "AUT" in the children, and when doing that I don't get an error, but it doesn not select anything.
With HTMLDoc.getElementsByName("Select")(0)
.Children(1).Selected = True
.Children(2).Selected = True
.Children(3).Selected = True
End With
Also tried the following, this doesn't give an error, but only selects the first option in the list.
With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
.Children(AUT).Selected = True
.Children(SET).Selected = True
.Children(TST).Selected = True
End With
This is strange, when I use this code, it selects the first two in the list, but not the third.
With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
.Children(all).Selected = True
End With
With HTMLDoc.getElementsByName("UFG.USER_TYPES")(0)
.Children(0).Selected = True
.Children(1).Selected = True
.Children(2).Selected = True
End With
The above code fixed it... whoopie!
I'm in the middle of writing a script that enters details into a sign up form.
The first name field of the form has the following html code:
<input name="firstname" class="text-input" id="input-text-view328" aria-describedby="form-input-text-error-view307-required" type="text" maxlength="50" placeholder="" data-event="blur" data-view-value="" data-stickit-id="stickit_47" autocomplete="off">
I can't seem to get the script to enter a value for this field. I have tried each of the following and none seem to work:
Set Fname = IE.Document.getElementsByName("firstname")
Fname.Value = "John"
Set Fname = IE.Document.getElementsByClassName("text-input")
Fname.Value = "John"
Set Fname = IE.Document.getElementByID("input-text-view328")
Fname.Value = "John"
The error i get is
"run-time error '438':
Object doesn't support this property or method"
Any idea what's going on here?
Since getElementsByName returns collection, you can access them with the index nos
IE.Document.getElementsByName("firstname")(0).Value = "John"
OR
Set Fname = IE.Document.getElementsByName("firstname")(0)
Fname.Value = "John"
OR
IE.Document.getElementByID("input-text-view328").Value = "John"
OR
IE.Document.querySelector("#input-text-view328").Value = "John"
I'm attempting to:
open a specific URL & pass log-in information
grab data from Excel and search specified data
once search is complete, manipulate a data field to correlating Excel data and execute several commands within the application
close IE or loop search for next cell in data
I've attempted using VBA forms and modules.
I found this code online which seemed to have worked once to pass my credentials, but I can't get it to work again.
These Objects all.email & all.password would be found in the source code on the webpage as the ID?
HTMLDoc.all.Email.Value = "email#example.com"
HTMLDoc.all.Password.Value = "ex5566"
Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Sub Login_2_Website()
Dim oHTML_Element As IHTMLElement
Dim sURL As String
On Error GoTo Err_Clear
sURL = "example.com"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True
Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = oBrowser.Document
HTMLDoc.all.Email.Value = "email#example.com"
HTMLDoc.all.Password.Value = "ex5566"
For Each oHTML_Element In HTMLDoc.getElementsByTagName("input")
If oHTML_Element.Type = "submit" Then oHTML_Element.Click: Exit For
Next
' oBrowser.Refresh ' Refresh If Needed
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
I think you can use the same code, which you use for finding the submit button, to find the e-mail and password elements. If you know which name or id these elements have (by checking the html code of the page), you can use for instance If oHTML_Element.Name = "password" then oHTML_Element.Value = "ex5566"
If the specific elements have an ID, you can also go directly to them by using oHTML_Element = document.getElementById("[id of element]")
oHTML_Element.Value = "password" This can also be done if they don't have an id, but only a name, but then you have to find out if the name is used multiple times.
The web developer can name their inputs, buttons, forms, ids whatever they want. The email could be named Email, or ID, or Username, or XYZ, this is why you must inspect the elements in the website so you can build your code accordingly. Lets take twitter for example.
<input class="js-username-field email-input js-initial-focus" type="text" name="session[username_or_email]" autocomplete="on" value="" placeholder="Phone, email or username">
The tag is an input tag, with a class name of js-username-field email-input js-initial-focus there is no ID on it, therefore you can not use HTMLDoc.getElementByID, you have to use HTMLDoc.getElementsByClassName or you could use HTMLDoc.getElementsByTagName but if there are more than 1 input you have to loop them and correctly detect the one you need.
Its easier than it sounds but you have to have some basic knowledge of HTML. Continuing with twitter, the tag for the password is:
<input class="js-password-field" type="password" name="session[password]" placeholder="Password">
Different class and different name to differentiate between the two. And finally the login/submit button:
<button type="submit" class="submit EdgeButton EdgeButton--primary EdgeButtom--medium">Log in</button>
With these 3 portions of the HTML elements, you can log in the following way:
HTMLDoc.getElementsByClassName("js-username-field email-input js-initial-focus")(0).Value = "email#example.com"
HTMLDoc.getElementsByClassName("js-password-field")(0).Value = "ex5566"
HTMLDoc.getElementsByClassName("submit EdgeButton EdgeButton--primary EdgeButtom--medium")(0).Click
What does the (0) mean? in HTML you can have many tags with the same class name, and they all are on an array when you call getElementsByClassName, since the login site only has 1 tag with those class names, the array position of "0" is the one you are looking for.
Again, the developer can name the class, the id, anything they want, therefore you want to inspect the website to properly code your script.
I'm trying to replicate something I was able to do in Excel in Google Sheets: Select multiple list values and record in same cell.
I used this video:
https://www.youtube.com/watch?v=8x6YUsl7Ld4&feature=youtu.be
And this code:
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from www.trumpexcel.com
' To Select Multiple Items from a Drop Down List in Excel
Dim Oldvalue As String
Dim Newvalue As String
On Error GoTo Exitsub
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
Target.Value = Oldvalue & ", " & Newvalue
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
And managed to get it working in Excel, only to find that the functionality would be lost in Google Sheets.
Please could you tell me the equivalent code in Google apps script and where to place it?
Here's the script to do the same through google-apps-script. Caveats though are
1. Data Validation should be enabled to Show warning and not Reject Input as shown below
2. After selecting multiple items, the Cell in consideration would show a warning.(I couldn't figure out how to turn this off easily).One way to lessen the annoying warning on the cell is to put a help context for the cell "Ignore any warnings" by checking the box Show validation help text: in the image above.
3. The behavior is applied to ALL ranges where there is data validation, so please take due care to apply ONLY to ranges that you care about.
function onEdit(e){
var editedRange=e.range;
var rule = editedRange.getDataValidation();
if(rule!=null) //Act only if the cell has a data validation
if (!(e.value.equals("") || e.oldValue == null)) //No need to do anything funky if user clears everything or if previous contents were empty
if(e.oldValue.indexOf(e.value) !=-1) //Check if new selected value has already been chosen before
editedRange.setValue(e.oldValue) //If already chosen then don't select again.
else
editedRange.setValue(e.oldValue+","+e.value) // Show old+new selection.
}
onEdit is a Simple trigger function that gets called every time there is an edit to the Spreadsheet(any individual Sheets ).
e is the Event Object that contains information about the edit that happened.
You can find more documentation about the same here.
Also this might help if you want to programmatically set a Data Validation.
You could create a dialog to show every available option as checkboxes and set the cell data based on the user selection.
Here is some example data:
and here how such dialog would behave:
To do that you must first create a script file with four functions. One to expose a menu to the dialog, another to show the dialog, a third to process and pass the options to the dialog, and the last one to set data in the cell sent from the dialog. See the code bellow:
function onOpen() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const multiselectMenu = {name: 'Select multiple', functionName: 'showSelectDialog'}
ss.addMenu("My Scripts", [multiselectMenu]);
}
function showSelectDialog(){
const template = HtmlService.createTemplateFromFile('dialog');
template.optionsData = getOptionsFromCurrentCell();
const html = template.evaluate();
SpreadsheetApp.getUi().showModalDialog(html, 'Select multiple');
}
function getOptionsFromCurrentCell(){
const validOptions = SpreadsheetApp
.getActiveRange() // everything that is selected
.getDataValidation() // all validation rules for that
.getCriteriaValues()[0] // the first criteria
.getValues() // the value for this criteria
.map(value => value[0]); // flatten in an one dimension array
const selectedOptions = SpreadsheetApp
.getActiveRange()
.getCell(1, 1) // first selected cell in the range
.getValue()
.split(',') // convert the cell string into an array
.map(str => str.trim()); // remove unwanted whitespace
const optionsData = validOptions.map(option => {
return {
value: option,
isSelected: selectedOptions.includes(option)
}
})
return optionsData;
}
function setOptionsForCurrentCell(selectedOptions){
const hasOptions = Array.isArray(selectedOptions)
&& selectedOptions.length > 0
const cellData = hasOptions
? selectedOptions.join(',') // creates a comma separated string
: '';
const cell = SpreadsheetApp.getActiveRange().getCell(1, 1);
cell.setValue(cellData);
}
Then you create a Html file inside the script editor to render the dialog and pass the selected options back to the spreadsheet. See:
<!DOCTYPE html>
<html>
<body>
<? for (const option of optionsData) { ?>
<input
type="checkbox"
class="option"
value="<?= option.value ?>"
<?= option.isSelected && "checked" ?>
>
<label><?= option.value ?></label><br>
<? } ?>
<div style="margin-top:10px;">
<input
type="button"
value="all"
onclick="setAll('check')"
/>
<input
type="button"
value="clear"
onclick="setAll('clear')"
/>
<input
type="button"
value="cancel"
onclick="google.script.host.close()"
/>
<input
type="button"
value="apply"
onclick="apply()"
/>
</div>
<script>
function setAll(value) {
const optionsEl = document
.querySelectorAll(".option");
for (const checkbox of optionsEl) {
checkbox.checked = value === 'check';
}
}
function apply(){
const checkedEls = document
.querySelectorAll(".option:checked");
const selectedValues = [];
for (const checkbox of checkedEls) {
if (checkbox.checked) {
selectedValues.push(checkbox.value);
}
}
google.script.run
.setOptionsForCurrentCell(selectedValues);
google.script.host.close();
}
</script>
</body>
</html>
That should work. If you want a step-by-step guide for this solution, check this post.
I'm trying logging verification, everything seems to be fine, but when I add the special characters string to another variable it causes an error to occur.
I'm trying to detect if a user is inputting special characters such as: !, . etc. something like that.
Here's my code,
<form action="" method="get"/>
username:<input type="text" name="user"/><br>
password:<input type="password" name="pass"/><br>
<input type="submit" value="Login">
</form>
<%
dim user,pass, spchar, getspchar
user=request.querystring("user")
pass=request.querystring("pass")
spchar = "!"
getspchar = spchar
if user = "" then
response.write("Please provide your first name")
elseif pass = "" then
response.write("Please provide your password")
elseif user = spchar or pass = spchar then
response.write(getspchar &" Special character not allowed")
elseif user <> "admin" or pass <> "admin" then
response.write("Invalid Username or Password")
else
response.write("welcome")
end if
%>
What you need to do is check to see if your special characters are in the list. Perhaps something like the following...
<%
Dim user, pass, specchars
'Put all your special characters in the following list...
user = Request.QueryString("user")
pass = Request.QueryString("pass")
specchars = "!£$%^"
If IsValid(user, specchars) And IsValid(pass, specchars) Then
Response.Write("Username and password are fine! Welcome!")
Else
Response.Write("Bad username or password.")
End if
'The reason I've given two arguments here is so that you can have different
'restricted characters for both the username and password...
Function IsValid(phrase, special)
Dim rv, c
For c = 1 to Len(specchars)
rv = (Instr(phrase, Mid(special, c, 1)) = 0)
Next
IsValid = rv
End Function
%>
Just as an aside, here, you're visually displaying your username and password in the query string which is tagged on to the end of your URL (something like www.example.com/default.asp?user=admin&pass=G0d); this isn't a good idea. Try at least using POST in your form instead of GET. If you do this, then you're going to have to look at changing to using Request.Form("controlname") ... and that's just scratching the surface.
Please remember that this is a very basic piece of code and I would not recommend using any structure like this for your security on the internet. You'll need to look into Secure Sockets Layer (SSL) and similar encryption.