I have a simple form for this scenario written in razor/webmatrix. I would like to have a user be able to login to an external website with the login credentials provided by my db.Query via a foreach loop. The login works if I don’t use a foreach loop. It simply returns the first row from the DB Query, and logs in. When I add the foreach loop, it opens the login page without any credentials. Any help would be appreciated. My code is below:
var selectQueryString = "SELECT user_id,password FROM user_table
var user_row = db.Query(selectQueryString);
<form name="UpdateOrRac" method="POST" action="Login Page URL would be here">
@foreach (var row in user_row){
<div>
<input name="txtUserID" value="@row.user_id" readonly="readonly" />
<input name="txtPassword" value="@row.password" readonly="readonly" />
<input type="submit" value="Login" />
</div>
}
</form>
With the foreach loop your page sends to the login page all the user/password pairs stored in your database together.
I think that you should select a user and populate with it the form.
Somenthing like:
Edit
In response to your comment, yes, but now your target is clearer.
To obtain a list of your acccounts with the possibility of login, the easiest way is to use a link to the Login page with a querystring with userid and password:
You can get the passed data in the Login.cshtml page with this statements:
If the security is a concern, you must consider that GET and POST are nearly the same (look at Is either GET or POST more secure than the other?)