Answered by:
Authenticate user from a existing user table

Question
-
User-1862500537 posted
How can use a existing table with the data of the user (user, password) to authenticate the user from the login page? I was checking this article http://mikepope.com/blog/DisplayBlog.aspx?permalink=2240 is that the best way to do it, using the websecurity helper?
Friday, July 8, 2016 11:09 PM
Answers
-
User325035487 posted
mgar
is that the best way to do it, using the websecurity helper?That could be one easy way.. i did it this way, and wrote a script to run through all users in my table to register them using the register a new user script on that site
var db = Database.Open("db"); var empsql = "SELECT UserID FROM Employees WHERE Active=1"; var employees = db.Query(empsql); string username = ""; string password = ""; foreach (var r in employees) { if (r.UserID != null) { username = r.UserID.ToLower(); password = r.UserID.ToLower(); if (!WebSecurity.UserExists(username)) { WebSecurity.CreateUserAndAccount(username, password, null, false); } } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, July 9, 2016 8:55 AM
All replies
-
User379720387 posted
create a new startersite from the template and look in the folder Admin for LogIn
The starter site has a complete functioning Simple membership implementation
Saturday, July 9, 2016 3:21 AM -
User325035487 posted
mgar
is that the best way to do it, using the websecurity helper?That could be one easy way.. i did it this way, and wrote a script to run through all users in my table to register them using the register a new user script on that site
var db = Database.Open("db"); var empsql = "SELECT UserID FROM Employees WHERE Active=1"; var employees = db.Query(empsql); string username = ""; string password = ""; foreach (var r in employees) { if (r.UserID != null) { username = r.UserID.ToLower(); password = r.UserID.ToLower(); if (!WebSecurity.UserExists(username)) { WebSecurity.CreateUserAndAccount(username, password, null, false); } } }
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Saturday, July 9, 2016 8:55 AM -
User-1862500537 posted
My UserID is 'varchar()' type so when I try to do this
if (r.UserID != null)
Gives me the error: BC30456 'UsetID' is not a member of 'Char'.
Saturday, July 9, 2016 6:20 PM -
User325035487 posted
Skip that if condition if you are sure you dont have any null values in that column
Sunday, July 10, 2016 5:36 AM -
User-1862500537 posted
Gives me the same error ( BC30456 'iduser' is not a member of 'Char', BC30456 'password' is not a member of 'Char'.) when I try to asign the username and password
username = r.iduser password = r.password
Monday, July 11, 2016 3:03 PM -
User-1862500537 posted
I was wrong in my syntax, sorry.
Monday, July 11, 2016 4:27 PM