Am having this problem from when I try to make information in a table as a variable.
If I write;
Username = "admin"
Password = "admin"
table = {["p_targetId"] = 0 ,["p_cmd"] = "getProductListSaved" , ["p_userName"] = Username, ["p_password"] = Password , ["p_data"] = {{}}}
Get_Info = rapidjson.encode(table)
I get
{"p_targetId":"0","p_cmd":"getProductListSaved","p_userName":"admin","p_password":"admin","p_data":[{}]}
which I want to get. But when I write;
Enter_Password = Controls.Enter_Password
Password = "admin"
table = {["p_targetId"] = 0 ,["p_cmd"] = "getProductListSaved" , ["p_userName"] = Username, ["p_password"] = Password , ["p_data"] = {{}}}
table["p_password"] = tostring(Enter_Password.String)
table2 = rapidjson.encode(table)
When in Textbox I write admin enter image description here , I get
{"p_targetId":"0","p_cmd":"getProductListSaved","p_userName":"admin","p_password":"","p_data":[{}]}
After reading some forums. It seems my input Textbox string is not being saved into local Password, thus in table will stay as "".
Is there a way to store "admin" in Textbox into a variable, also changes when another string is in Textbox?
Found the solution, basically needed to make a function with string.format() to save my Input in a variable.
if Enter_Password.String ~= "" then
Password = string.format("%s", Enter_Password.String)
table["p_password"] = Password
end
Related
I am using below groovy code to select a row with a given username and password from mysql db.
For example,
I am searching for below user. Password is stored in db as a SHA1 hashed password.
Name - test7
password - {SHA}01132E914B722741CC3823D0BEACB8364EEAC376
Below is the groovy code which is trying to retrieve the record and failing as I am not able to fetch the record.I suspect the sql query constructed is wrong. SecurityUtil class is just decrypting and returning a plaintext password back as a positional parameter to the query. We are
using the sha1 method of mysql to generate the hash and prefix with string {SHA1} and then trying to retrieve the record.
sql.eachRow("SELECT id FROM users WHERE userName = ? AND password =CONCAT({SHA1},sha1(?))", [username, SecurityUtil.decrypt(password)]) {
authId = String.valueOf(it.id)
}
Welp if SQL doesn't want to play do it in Groovy. Using GStrings you get the same protection as prepared calls so no SQL Injection issues, and you can more easily do groovy operations:
sql.eachRow("SELECT id FROM users WHERE userName = ${userName} and password = ${'{SHA}' + SecurityUtil.decrypt(password)}") {
authId = String.valueOf( it.id )
}
The prepared statement syntax route:
sql.eachRow("SELECT id FROM users WHERE userName = ? and password = ?", [username, "{SHA}${SecurityUtil.descrypt(password)}"]) {
authId = String.valueOf( it.id )
}
sql.eachRow("SELECT id FROM users WHERE userName = ? AND password =CONCAT('{SHA1}',sha1(?))", [username, SecurityUtil.decrypt(password)]) {
authId = String.valueOf(it.id)
}
You may need to put the {SHA} in quotes for use in the concat operator.
i want to make "instagram Direct Message SENDING MECRO"
URL = www.instagram.com/direct/inbox
driver.FindElementByXPath("/html/body/div[1]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button/div/svg").Click
WHEN I open the link, and copy&paste the xpath,
then my code run well
However, after run one time,
run my code again,
then 'NoSuchElementError'... why...? what shoud i do..?
(i also use selenium)
full code :
Sub Sending_DM()
Dim driver As Selenium.ChromeDriver
Dim username As String, Login_ID As String, Login_PW As String
Set driver = New Selenium.ChromeDriver
driver.Start
driver.Wait (2000)
username = Sheet3.Range("B2").Value 'B2 = User ID = username
Login_ID = Sheet3.Range("a1").Value
Login_PW = Sheet3.Range("a2").Value
driver.Get "https://www.instagram.com/" & username
'-----------Login
driver.FindElementByXPath("//*[#id=""loginForm""]/div/div[1]/div/label/input").SendKeys (Login_ID) ' MY INSTAGRAM ID
driver.FindElementByXPath("//*[#id=""loginForm""]/div/div[2]/div/label/input").SendKeys (Login_PW) ' My instagram PW
driver.FindElementByXPath("//*[#id=""loginForm""]/div/div[3]").Click
driver.Wait (4000)
driver.Get "https://www.instagram.com/direct/inbox/"
'-----------Sending DM
driver.FindElementByXPath("/html/body/div[1]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button/div/svg").Click
driver.FindElementByXPath("/html/body/div[6]/div/div/div[2]/div[1]/div/div[2]/input").SendKeys (Sheet3.Range("c1"))
driver.FindElementByXPath("/html/body/div[6]/div/div/div[1]/div/div[2]/div/button/div").Click
driver.Wait (1000)
driver.FindElementByXPath("/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div[2]/textarea").SendKeys (Sheet3.Range("c2").Value) 'Sheet3.range("c2") = recipient ID
driver.FindElementByXPath("/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div[3]/button").Click
Sheet3.Range("d2") = "o" 'Sending Check
End ()
okay we are running into wrong locator issue.
replace this line
driver.FindElementByXPath("/html/body/div[1]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button/div/svg").Click
with this :
driver.FindElementByXPath("/html/body/div[1]/section/div/div[2]/div/div/div[1]/div[1]/div/div[3]/button/div/*").Click
Isn't my coding typing wrong way? I need create an update button so user can edit the information by using Matlab. After update, the button need connect to mySQL server 5.6 and ODBC connector.
This is my code:
% --- Executes on button press in update.
function update_Callback(hObject, eventdata, handles)
% hObject handle to update (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%Display dialog box to confirm save
choice = questdlg('Confirm update to database?', ...
'', ...
'Yes','No','Yes');
% Handle dialog box response
switch choice
case 'Yes'
%Set preferences with setdbprefs.
setdbprefs('DataReturnFormat', 'cellarray');
%Make connection to database.
conn = database('animal_cbir', '', '');
%Test if database connection is valid
testConnection = isconnection(conn);
disp(testConnection);
fileID = getappdata(0,'namevalue');
imageID = fileID;
name = get(handles.edit11,'String');
commonName = get(handles.edit1,'String');
scientificName = get(handles.edit2,'String');
class = get(handles.edit3,'String');
diet = get(handles.edit4,'String');
habitat = get(handles.edit5,'String');
lifeSpan = get(handles.edit6,'String');
size = get(handles.edit7,'String');
weight = get(handles.edit8,'String');
characteristic = get(handles.edit10,'String');
tablename = 'animal';
colnames ={'imageID','name','commonName','scientificName','class','diet','habitat','lifeSpan','size','weight','characteristic'};
data = {imageID,name,commonName,scientificName,class,diet,habitat,lifeSpan,size,weight,characteristic};
disp (data);
whereClause = sprintf(['where imageID = "%s"'],fileID);
update(conn,tablename,colnames,data,whereClause);
updateSuccess = helpdlg('Existing animal species successfully updated in database.');
commit(conn);
case 'No'
end
Error I am getting:
No method 'setInt' with matching signature found for class 'sun.jdbc.odbc.JdbcOdbcPreparedStatement'.
Hope that anyone can help me solve it.
In my asp.net and vb.net web application form ; the drop down list for Main Contact holds a list of names. This list is different for different user who are logged in to the application.
Data are populated by select query from database fields. (select query fetches data by Innerjoining two tables- EmployerUser table & User table. Primary key of User table is ID which is a foreign Key in the EmployerUser table named UserID.)
In Front end ASP.net coding is
<div class="form-element">
<label>
Main contact (required)
</label>
<asp:DropDownList ID="comMainContact" runat="server" CssClass="chosen" EnableViewState="True"
DataTextField="name" DataValueField="id" />
</div>
In Back end VB.net coding for the drop down list is
comMainContact.DataSource = LocalHelper.CachedEmployerUserList(LocalHelper.UserEmployerID)
comMainContact.DataBind()
Public Shared Function CachedEmployerUserList(ByVal employerid As Integer) As DataTable
Dim CacheName As String = "helper_cachedemployeruserlist_" & CStr(employerid)
Dim DataList As DataTable = Nothing
Try
DataList = HttpContext.Current.Cache.Item(CacheName)
Catch
End Try
If DataList Is Nothing Then
DataList = Core.DB.GetData("SELECT [User].id AS 'id', [User].name + ' ' + [User].Surname AS 'name' FROM EmployerUser INNER JOIN [User] ON EmployerUser.userid = [User].id WHERE [User].deleted = 0 AND [User].active = 1 AND [User].emailverified IS NOT NULL AND EmployerUser.employerid = #employerid ORDER BY [User].surname, [User].name", Core.DB.SIP("employerid", employerid))
HttpContext.Current.Cache.Insert(CacheName, DataList, Nothing, DateAdd(DateInterval.Minute, 1, Now), System.Web.Caching.Cache.NoSlidingExpiration)
End If
Dim FinalList As DataTable = DataList.Copy
Return FinalList
End Function
The problem is : This coding does not set a default value for the Main Contact . I want to set a default value in drop down list for the Main Contact. In most of the cases the default value is the user himself. So it would be ideal if the current user is set as default value in the drop down list as well as the user is also able to change value from the drop down list if himself is not the Main Contact.
How can I do that.
I can separately determine who is the currently logged in user.
The coding to determine current user is (Current logged in User can be determined via select query which fetches data from User table.)
Public Class User
Public Shared Function UserFullName(ByVal User As Mypeoplebiz.User, Optional ByVal Title As Boolean = True) As String
If Title Then
Return Core.DB.GetString("SELECT name FROM Title WHERE id = #titleid", Core.DB.SIP("titleid", User.TitleID)) & " " & User.Name & " " & User.Surname
Else
Return User.Name & " " & User.Surname
End If
End Function
End Class
How can I set current user is set as default value in the drop down list and give the user the option of changing value from the drop down list .
Appreciate your help.
Thanks
Set the SelectedValue property of the dropdown list to the username string:
comMainContact.SelectedValue = UserFullName(arguments)
See https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listcontrol.selectedvalue(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-2
The following lines of code solved my problem. So I want to share it if any one have similar problem.
Private strUserName As String = ""
strUserName = Core.DB.GetString("SELECT name + ' '+surname FROM [user] WHERE id = " & LocalHelper.UserID)
comMainContact.DataSource = LocalHelper.CachedEmployerUserList(LocalHelper.UserEmployerID)
comMainContact.DataBind()
comMainContact.SelectedIndex = comMainContact.Items.IndexOf(comMainContact.Items.FindByText(strUserName))
Hope you will find the post useful
If i had a login page that got user input for username and password, how would i post that information to another page that is gonna be used to store subs and procedures so other pages will include that page so I can minimise the amount of times i type up a connection string.
So I have login.asp which i want to post login credentials to include.asp which will never be opened by if users login details are correct it would then be directed to table.asp. If incorrect it should show an error message in the login.asp page.
I've provided the code for include.asp file which will never be seen by a user below
Dim objCon, SQL, objRS
'Connect to Database
sub connect()
Set objCon = CreateObject("ADODB.Connection")
Set objRS = CreateObject("ADODB.Recordset")
objCon.Open "Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;User ID=xxxx;Initial Catalog=Customer;Data Source=xxxx"
SQL = "SELECT * FROM Customer"
objRS.open SQL, objCon
end sub
sub connectionClose()
objRS.close
objCon.close
end sub
let me post with code tag so it helps.
so u got login.asp,validateLogin.asp, table.asp ( they all got include.asp)
Login.asp post the credentials to validatelogin.asp
once in validatelogin.asp
dim username : username = request.form("username")
dim password: password = request.form("password")
'here for security purpose u will want to replace all the single quote in username and password with 2x single quote (you do that to avoid SQL injection form bots / hackers
username = replace(username ,"'","''")
password = replace(password,"'","''")
sqlValidateUser = "SELECT top 1 * FROM Customer where username='"&&"' and password = ''"
set rsValidateUser = objCon.execute(sqlValidateUser)
if not rsValidateUser.eof then
session("authentified") = "1"
response.redirect("table.asp")
response.end()
else
response.redirect("YOUR_ERROR_PAGE.asp")
response.end()
end if
rsValidateUser.close
then in your include.asp u will want something like :
'Validating if your NOT on login.asp or loginvalidate.asp ... if not Check if your logged in ... if not redirect to error page or login form
if not instr(lcase(request.servervariable("url")),"login.asp") > 0 and not instr(lcase(request.servervariable("url")),"validatelogin.asp") > 0 then
if session("authentified") = "1" then
response.redirect("your_Error_page.asp")
end if
end if
not 100% sure about the include.asp code i did not validate any of it but it should look like that
Under your root folder create an \includes folder.
Within \includes add a "functions.asp" page and put your common data access functions in that page. Include NO HTML - just server side script.
In your authentication page, add #include directives that point to your includes folder: example:
<!-- #include file = "../includes/functions.asp" -->
Then from your auth page you call any functions defined in functions.asp.