Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 28, 2010 11:19 PM by Vimpyboy
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.
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.
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:
The method looks like this:
InitializeDatabaseConnection(string connectionString, string providerName, string userTableName, string userIdColumn, string userNameColumn, bool autoCreateTables)
The method looks like this:
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.
Jul 28, 2010 03:31 PM|LINK
[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?
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:
Hope this helps.
Jul 28, 2010 08:57 PM|LINK
What if my Username and Password are in the same table as the other user details?
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....
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.
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.