Note that there are some explanatory texts on larger screens.

plurals
  1. POOperator '==' cannot be applied to operands of type 'WebMatrix.Data.DynamicRecord'
    primarykey
    data
    text
    <p>I'm trying to do a very simple username and password validation against a table called users (containinig an <code>id(int) username(nchar(10)</code>) and <code>password(char(32)</code>) using Razor but I'm encountering this error:</p> <pre><code>Operator '==' cannot be applied to operands of type 'WebMatrix.Data.DynamicRecord' and 'HasherMD5Main' </code></pre> <p>I created a .cs class that does an md5 hash (<code>HasherMD5Main</code>) which returns the value passed as a string (please no comments on security, this is not going into any production environments) and I'm hashing the entered password and then doing a lookup in the db.</p> <h2>Code</h2> <pre><code>@{// Initialize page var enteredusername = ""; var enteredpassword = ""; var ErrorMessage = ""; // If this is a POST request, validate and process data if( IsPost ) { enteredusername = Request.Form["enteredusername"]; enteredpassword = Request.Form["enteredpassword"]; var hash = new HasherMD5Main( enteredpassword ); if( enteredusername.IsEmpty() || enteredpassword.IsEmpty() ) { ErrorMessage = "You must specify a username and password."; } else { var db = Database.Open( "MyConnectionString" ); var passwordquery = db.QuerySingle( "SELECT password FROM users WHERE username = @0", enteredusername ); if( passwordquery == hash ) { Response.Redirect( "/Success" ); } else { Response.Redirect( "/Failure" ); } } } } @if( ErrorMessage != "" ) { &lt;p&gt;@ErrorMessage&lt;/p&gt; &lt;p&gt;Please correct the errors and try again.&lt;/p&gt; } &lt;form method="post" action=""&gt; &lt;fieldset&gt; &lt;legend&gt;Log In to Your Account&lt;/legend&gt; &lt;ol&gt; &lt;li&gt; &lt;label&gt;Username:&lt;/label&gt; &lt;input type="text" id="enteredusername" name="enteredusername" /&gt; &lt;/li&gt; &lt;li&gt; &lt;label&gt;Password:&lt;/label&gt; &lt;input type="password" id="enteredpassword" name="enteredpassword" /&gt; &lt;/li&gt; &lt;li&gt; &lt;p&gt; &lt;input type="submit" value="login" /&gt;&lt;/p&gt; &lt;/li&gt; &lt;/ol&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>Any ideas on how I can simply validate if the hashed password my app comes up with matches the hash stored in the db?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload