I have an assignment for one of my classes where I need to bypass CSRF protection and login with a specific account even if the user inputs different credentials. Right now I did it in a kind of hack-y way that works when there is no CSRF protection (place an invisible submit button for my form on top of the iframe's submit button). Anyway, so how would I overwrite the username and password fields (using Jquery I presume) of the iframe when the login button (in the iframe) is pressed?
mytest.com:
<html>
<head><title>mytest.com</title></head>
<body>
<iframe id="testFrame" src="test.com" allowfullscreen width="110%" height="900px"></iframe>
</body>
</html>
test.com:
<form method="post" class="form-inline" id="form0">
<input id="user" name="user" type="text" placeholder="username" required>
<input id="pass" name="pass" type="password" placeholder="password" required>
<button id="submitBut" type="submit" formaction="test.com">login</button>
</form>
Related
Good morning,
I'm doing a basic website for the university.
I should provide a login form where the user can insert username and password... If those are correct a cookie is saved with username value; thanks to this cookie, when the user closes the session and opens again the browser to login, the username field is already there (I did this with a php script inside the form).
The only problem is that the button that should clear both the textfields in the form doesn't work.
<form name="f" action="controlAndErrorLogin.php" method="POST">
<p>Username: <input type="text" name="username" value=<?php if(isset($_COOKIE["username"])){echo "\"".$_COOKIE["username"]."\"";}else{echo "\"\"";}?>>
</p>
<p>Password: <input type="password" name="password" value=""></p>
<p>
<input type="submit" value="OK">
<input type="reset" value="PULISCI" onclick="document.getElementById('username').value = '';">
</p>
</form>
What is the problem?
Thanks
First of all, your input field is missing the id that you are trying to select it by.
Second, a reset button resets form fields to the default value they had specified in the initial HTML. You specified the user name in there, not an empty value - so that’s what the field will get reset to.
Third, .value = '' only resets the current value of the element, but not the default value. You need to set the actual defaultValue property, to achieve that.
<form name="f" action="controlAndErrorLogin.php" method="POST">
<p>Username: <input type="text" id="username" name="username" value="foo"></p>
<p>Password: <input type="password" name="password" value=""></p>
<p>
<input type="submit" value="OK">
<input type="reset" value="PULISCI"
onclick="document.getElementById('username').defaultValue = '';">
</p>
</form>
try to add attribute id="username" in the input tag with name="username"
I have some comment forms that I want to not be used unless the user is logged in with Google+. I initially have the "submit" button on my forms hidden by the CSS display:none property. I call javascript when the user logs in to change it back to display:inline.
Is this a valid way to prevent anonymous users from posting, or am I still vulnerable by leaving the rest of the comment form open for writing and whatnot...is there some clever way to submit the form without the submit button?
<form action="" method="post" name="form1" id="make">
<fieldset>
<legend id="makelegend">Log in to Post a Reference</legend>
<input type="hidden" name="loginname" id="loginname" />
<input type="hidden" name="logintype" id="logintype" />
<input type="hidden" name="loginspecial" id="loginspecial" />
<input type="hidden" name="reply" id="reply" value="0" />
<input type="hidden" name="identity" id="identity" value="<?php echo htmlspecialchars($_GET['pageno']); ?>" />
<p><label for="posneg">Positive or Negative?
<select name="posneg">
<option value="p">Positive</option>
<option value="n">Negative</option>
</select></label></p>
<textarea name="comment" rows="5" cols="70"></textarea>
<input type="submit" id="submitter" value="POST" style="display:none;" />
</fieldset>
</form>
It is ABSOLUTELY NOT safe! You're just not displaying the data to the user, but anyone who looks at the code can still find it - or just send the request manually. I can't stress this enough: ALWAYS use server-side validation! It's fine to validate things in the browser as well, but it's not a substitute for proper security measures.
I have Internet service. They provide Login page for internet Login (Ex: i.e. http://globalNetSolutions.com/Login.html). If i am buying one website (Ex : i.e. http://MyNetSolutions.com/Login.html) is it possible to From my website username & password to http://globalNetSolutions.com/Login.html website (because of that 3rd party site not looking grate.i want login from my own website.)
I changes are needed where do i change my code :
<form action="" method="post" onSubmit="">
<h2>LOGIN TO <span class="red"><strong>MyNetSolutions</strong></span></h2>
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="choose a username...">
<label for="password">Password</label>
<input type="password" id="password" name="password" placeholder="choose a password...">
<button type="submit">LOGIN</button>
</form>
You can use oauth for lo-gin purpose. But problem with that is you can not use user password for encryption. Id you do not care about that, then you can go ahead with oauth approach.
We have an internal application that requires the same username/password across the board.
However, if the login fails too many times, then the account is locked for that username.
We can't change the lockout because that will affect the public facing site as well.
I have been asked to come up with a way to essentially, click a button and auto-login.
Initial research has brought me to this script... (Credit)
<!doctype html>
<!-- saved from url=(0014)about:internet -->
<html>
<title>Auto Login</title>
</head>
<body>
<form id="loginForm" name="loginForm" method="post" action="http://mail.google.com">
<select name="uni_url" id="logServer" class="validate[required]">
<option class="" value="" fbUrl="" cookieName="" >
Test_en
</option>
</select>
<input id="loginName" name="name" type="text" value="Username" class="" />
<input id="loginPassword" name="password" type="password" value="ExamplePassword" class="" />
<input type="hidden" id="loginKid" name="kid" value=""/>
</form>
<script>document.loginForm.submit();</script>
</body></html>
...but I can't seem to get it to work for me.
So, I found another option where I can create a small html file (form) with a submit button, that does - onload="form1.submit();", and this could basically log me into this website without having to key in any login information.
Not sure where to start with mimicking a login form like this and need a good direction to get started in.
Thoughts?
Let's assume your existing login form looks like this:
<form action="/login.php" method="post" id="loginform">
<input type="text" name="username" />
<input type="password" name="password" />
<input type="submit" />
</form>
On your "auto-login" (which is really an auto-submit) page you want to mimic the same structure as before but:
Add in values to be submitted (static username and password?)
Optionally remove the submit button (if you know your users have JS enabled then you can get rid).
Add some JS that automagically submits the form for you.
That might give us something like this:
<form action="/login.php" method="post" id="loginform">
<input type="text" name="username" value="gvee" />
<input type="password" name="password" value="hunter2" />
</form>
<script type="text/javascript">document.forms[0].submit()</script>
The javascript will essentially look for the first form on the page (forms[0]) and submit that.
Update
Upon further inspection your existing login form is a bit of a funny onion. Instead of submitting the form directly, it's calling a function called doLogin() that sets certain hidden properties.
Therefore, instead of submitting the form, we should mimic the same behaviour (i.e. call doLogin() instead of .submit()).
One key thing here is that you'll want to only call the function after it has been declared. Simplest solution is to put our added bit of script at the very bottom of the HTML.
<script type="text/javascript">doSubmit();</script>
How do I get the browser to ask the user to remember the password when using ng-submit in an AngularJS single page application.
My Form:
<form action="/#/dashboard/login" onsubmit="return false;" ng-submit="login()" name="loginForm">
<input type="text" required id="username" name="username" ng-model="username" autocomplete="on" placeholder="Username" value="">
<input type="password" required id="password" name="password" ng-model="password" autocomplete="on" placeholder="Password" value="">
<button type="submit" class="btn">Submit</button>
</form>
Any Ideas?
UPDATE
I just added the action to get the browser to recognise the form and trick it into remembering the password. (which obviously didn't work.) The form works fine without the action. The onsubmit="return false;" prevents the execution of the action. Only the ng-submit is doing anything.
Your code is ok, but you need to add the name attributes to your inputfields, such as:
<input type="text" name="username" ...>
and
<input type="password" name="password" ...>
The problem is the dynamically generated login form. After putting the form into the index.html it worked as expected. I guess this is a security issue.
The problem that then occurred was that the ngModels didn't get updated on autofill. After some searching I found the solution to that problem here. In AngularJS 1.2+ this is supposed to be fixed.
Your form HTML is a bit confusing.
<form action="/#/dashboard/login" onsubmit="return false;" ng-submit="login()" name="loginForm">
When the form is submitted do you want it to go to /#/dashboard/login or do ng-submit="login()" ? At the moment, the ng-submit is being ignored in favour of the form action. If you want it to go to /#/dashboard/login as a new page, then just remove the ng-submit and onsubmit attributes and it will work as normal.
If you want it to do ng-submit="login()", then remove the action and onsubmit attributes. Angular automatically prevents form submission when a form with ng-submit does not have an action attribute too. Doing it this way will stop the browser remember password prompt as the form isn't actually submitted anywhere. I guess this is an area where browsers have yet to catch up to the era of the single page application, there's no direct fix for it that I'm aware of.
A workaround would be to have a separate hidden form in the HTML, set the username/password there to the same as the user enters in main form, and then submit that hidden form to an iframe at the same time as ng-submit is called - have a look at How can I get browser to prompt to save password? for ideas about how to do it.
I didn't have to do anything special. But I noticed that while MS Edge and Firefox worked well and offered to remember credentials Chrome didn't.
So simply by providing name attribute to the login form and to username and password it seemed to work fine in Chrome. Autocomplete is on as well. Example:
<form method="post" class="form-horizontal well" ng-submit="login()">
<div class="form-group">
<label class="col-sm-4 control-label">Email Address</label>
<div class="col-sm-8">
<input name="username" ng-model="email" type="email" class="form-control" placeholder="user#example.com" autofocus="autofocus" autocomplete="on" required />
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Password</label>
<div class="col-sm-8">
<input name="password" ng-model="password" type="password" autocomplete="on" class="form-control" required />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-4 col-sm-8">
<button type="submit" class="btn btn-primary">Log on</button>
</div>
</div>
</form>
PS: I'm using Chrome Version 45.0.2454.93 m
The culprit is "return false;" on onsubmit. Remove that, and you're good to go. ng-submit takes care of the rest, such as not actually submitting the form when you hit enter in a field or click the submit button.