I have a pre-existing database built with sql server express edition. I have been able to use Webmatrix helpers (ie. twitter, grid, xbox live id) to do some cool dynamic stuff with my database. However, when it comes to WANTING to use simple authentication
(the one built into the "webpages_membership" object) I fail.
Would anyone be willing to give me a step by step breakdown of how to overload a simple auth. function so that it looks at my database for passwords, usernames, etc...? Is overload the right term?
Are you using the WebSecurity helper? There's some API ref in the
quickref. Not sure if that's what you're looking for. There are also a few examples in the
Security chapter of the book, plus you can have a peek at the security/login pages that are generated in the template.
What you need to do is to use that method in your own _start.cshtml (it´s like Application_Start in global.asax), and modify it so it works for your own database. You will just have to specify the right tale and columns and it should work.
Mikael Söderström
http://weblogs.asp.net/mikaelsoderstrom
http://www.twitter.com/vimpyboy
The reason I set the autoCreateTables to false is becuase I already have tables with "password", "password verify", "password expire date" as well as, "roles - admin, employee, client".
Do I have to set "autoCreateTables" to true? Does this mean I have to merge exsisting table data into the new table data? The reason I can't just use what's given is becuase the database is already populated with many users records and realtional data.
Simple membership is designed to work with exactly what you describe, it needs just enough information so that it can work with your existing user tables.
What if my Username and Password are in the same table as the other user details?
Example
In that image you have everything but your password.
What if your password (in that example) existed inside your user table? Your example deffinetly cleared something up - but I am still confused about this "asccociate" part...
</div> </div></div><div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1c1e19bb-a903-41ae-b3af-3048f7ec08c8">
</div><div style="padding: 0px; margin: 0px; display: inline; float: none;">You gave it the table name, the id, and the coloum name of the users (Username).</div><div style="padding: 0px; margin: 0px; display: inline; float: none;"> But again, what if I needed
to associate a password that already exsisted in the User table?
</div><div style="padding: 0px; margin: 0px; display: inline; float: none;">
</div></div><div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;">
</div>
That won't work. We don't know how your store your passwords and how you handle roles. The assumption is that you are have profile data (i.e. your user table) and you want to buy into our membership system (i.e password hasing and salting, and roles). We
can't take over your existing membership system we can only supplement it.
I would recommend writing a custom membership provider in this case. Then you will have full control over everything. Remember that SimpleMembershipProvider is exactly what it says - simple.
Mikael Söderström
http://weblogs.asp.net/mikaelsoderstrom
http://www.twitter.com/vimpyboy
Erik5388
Member
81 Points
84 Posts
Overloading Simple Authentication in Webmatrix
Jul 27, 2010 07:30 PM|LINK
I have a pre-existing database built with sql server express edition. I have been able to use Webmatrix helpers (ie. twitter, grid, xbox live id) to do some cool dynamic stuff with my database. However, when it comes to WANTING to use simple authentication (the one built into the "webpages_membership" object) I fail.
Would anyone be willing to give me a step by step breakdown of how to overload a simple auth. function so that it looks at my database for passwords, usernames, etc...? Is overload the right term?
Thanks for your help.
webmatrix authentication Helpers SQL Express Database Overload
zettersten.com
client side dev
canvas/html5/js/css
mikepope
Contributor
5803 Points
1155 Posts
Microsoft
Re: Overloading Simple Authentication in Webmatrix
Jul 28, 2010 02:57 AM|LINK
Are you using the WebSecurity helper? There's some API ref in the quickref. Not sure if that's what you're looking for. There are also a few examples in the Security chapter of the book, plus you can have a peek at the security/login pages that are generated in the template.
webmatrix documentation
Vimpyboy
Contributor
3212 Points
651 Posts
MVP
Re: Overloading Simple Authentication in Webmatrix
Jul 28, 2010 07:44 AM|LINK
The magic happens in WebSecurity.InitializeDatabaseConnection.
If you create a site using the starter template, you can find an example of that in _start.cshtml:
What you need to do is to use that method in your own _start.cshtml (it´s like Application_Start in global.asax), and modify it so it works for your own database. You will just have to specify the right tale and columns and it should work.
http://weblogs.asp.net/mikaelsoderstrom
http://www.twitter.com/vimpyboy
Erik5388
Member
81 Points
84 Posts
Re: Overloading Simple Authentication in Webmatrix
Jul 28, 2010 03:31 PM|LINK
My Code...
[code]WebSecurity.InitializeDatabaseConnection(connectionString, "System.Data.SqlClient", "Users", "LegacyId", "UserName", false);[/code]
The reason I set the autoCreateTables to false is becuase I already have tables with "password", "password verify", "password expire date" as well as, "roles - admin, employee, client".
Do I have to set "autoCreateTables" to true? Does this mean I have to merge exsisting table data into the new table data? The reason I can't just use what's given is becuase the database is already populated with many users records and realtional data.
So what do I do?
zettersten.com
client side dev
canvas/html5/js/css
davidfowl
Contributor
2676 Points
605 Posts
Microsoft
Re: Overloading Simple Authentication in Webmatrix
Jul 28, 2010 05:25 PM|LINK
Simple membership is designed to work with exactly what you describe, it needs just enough information so that it can work with your existing user tables.
Take a look at matthew's blog:
http://blog.osbornm.com/archive/2010/07/21/using-simplemembership-with-asp.net-webpages.aspx
Hope this helps.
Senior SDE, ASP.NET Team, Microsoft
Erik5388
Member
81 Points
84 Posts
Re: Overloading Simple Authentication in Webmatrix
Jul 28, 2010 08:57 PM|LINK
What if my Username and Password are in the same table as the other user details?
Example
In that image you have everything but your password.
What if your password (in that example) existed inside your user table? Your example deffinetly cleared something up - but I am still confused about this "asccociate" part...
FOR MORE EXPLINATION OF MY PROBLEM....
<div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:78d0f466-2d32-458b-91c7-02d9a9bd1a09"> <div style="border: 1px solid rgb(0, 0, 128); color: rgb(0, 0, 0); font-family: 'Courier New',Courier,Monospace; font-size: 10pt;" mce_style="border: 1px solid #000080; color: #000000; font-family: 'Courier New',Courier,Monospace; font-size: 10pt;"> <div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); max-height: 300px; overflow: auto;" mce_style="background: none repeat scroll 0% 0% #dddddd; max-height: 300px; overflow: auto;">- WebSecurity.CreateUserAndAccount(username, password
- new{FirstName = fname, LastName = lname, Email = email, StartDate = DateTime.Now,
Bio = bio});
</div> </div></div><div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:78d0f466-2d32-458b-91c7-02d9a9bd1a09"></div><div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;">You alread told "WebSecurity" to look for the username in the user table.</div><div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;"> View below...</div><div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;">
</div><div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;">
</div><div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;"><div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1c1e19bb-a903-41ae-b3af-3048f7ec08c8"> <div style="border: 1px solid rgb(0, 0, 128); color: rgb(0, 0, 0); font-family: 'Courier New',Courier,Monospace; font-size: 10pt;"> <div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); max-height: 300px; overflow: auto;">
- //Set up Simple Membership
- WebSecurity.InitializeDatabaseFile("SecurityDemo.sdf",
"Users",
"UserID",
"Username",
true);
</div> </div></div><div style="padding: 0px; margin: 0px; display: inline; float: none;" id="scid:9ce6104f-a9aa-4a17-a79f-3a39532ebf7c:1c1e19bb-a903-41ae-b3af-3048f7ec08c8"></div><div style="padding: 0px; margin: 0px; display: inline; float: none;">You gave it the table name, the id, and the coloum name of the users (Username).</div><div style="padding: 0px; margin: 0px; display: inline; float: none;"> But again, what if I needed to associate a password that already exsisted in the User table?
</div><div style="padding: 0px; margin: 0px; display: inline; float: none;">
</div></div><div style="padding: 0px; margin: 0px; display: inline; float: none;" mce_style="padding: 0px; margin: 0px; display: inline; float: none;">
</div>
zettersten.com
client side dev
canvas/html5/js/css
davidfowl
Contributor
2676 Points
605 Posts
Microsoft
Re: Overloading Simple Authentication in Webmatrix
Jul 28, 2010 10:16 PM|LINK
That won't work. We don't know how your store your passwords and how you handle roles. The assumption is that you are have profile data (i.e. your user table) and you want to buy into our membership system (i.e password hasing and salting, and roles). We can't take over your existing membership system we can only supplement it.
Senior SDE, ASP.NET Team, Microsoft
Vimpyboy
Contributor
3212 Points
651 Posts
MVP
Re: Overloading Simple Authentication in Webmatrix
Jul 28, 2010 11:19 PM|LINK
I would recommend writing a custom membership provider in this case. Then you will have full control over everything. Remember that SimpleMembershipProvider is exactly what it says - simple.
http://weblogs.asp.net/mikaelsoderstrom
http://www.twitter.com/vimpyboy