Rank: Member
Groups: Registered
Joined: 6/5/2020(UTC) Posts: 12 Thanks: 4 times
|
Hello, I have some problems setting a "Database Authentication" model and can not find out why. What I did: 1) set security provider to "Database Authentication" and set "Use custom security script" to True. 2) Write the following script (I left commented text, because I tried different scenarios) Quote: // string connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + user.Security.Repository.RepositoryPath + "\\Databases\\Northwind.mdb;Persist Security Info=False"; // string connectionString = "Provider=MSOLEDBSQL;Server=127.0.0.1;Database=EPKT;UID=sa;PWD=Bla"; // string connectionString = "Provider=SQLOLEDB.1;Data Source=127.0.0.1;Initial Catalog=EPKT;User ID=sa;Password=Bla;Login Prompt=False"; connetionString = "Data Source=127.0.0.1;Initial Catalog=EPKT;User ID=sa;Password=Bla"
// OleDbConnection connection = new OleDbConnection(connectionString); // connection.Open();
SqlConnection connection = new SqlConnection(connetionString); connection.Open();
// OleDbCommand command = new OleDbCommand(string.Format("select 1 from tUsers where UserID = {0} and Password = {1}", Helper.QuoteSingle(user.WebUserName), Helper.QuoteSingle(user.WebPassword)), connection); // OleDbCommand command = new OleDbCommand("select 'demo' from tUsers where UserID = 'admin' and Password = 'admin'"), connection); SQLCommand command = new SQLCommand("select 'demo' from tUsers where UserID = 'admin' and Password = 'admin'"), connection);
object group = command.ExecuteScalar();
if (group != null && group != DBNull.Value){ // user.AddSecurityGroup((string)group); user.AddSecurityGroup("demo"); }else { user.Error = "User unknown from the database."; }
As I can see query to database is not executed so it is probably problem in connection string or driver ? Is there any log file that can be checked for such errors ?
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
if you use the SQLServer driver, connection string is like: Server=myServerAddress;Database=myDatabase;Trusted_Connection=True
to test a login, the best is to use the 'Test a login' property in the Configuration->Configure Web Security dialog. you can change the user name and password.
|
|
|
|
Rank: Member
Groups: Registered
Joined: 6/5/2020(UTC) Posts: 12 Thanks: 4 times
|
For script: Quote:// http://csharp.net-inform...ql-server-connection.htmconnectionString = "Server=localhost;Database=EPKT;Trusted_Connection=True" ReportExecutionLog log = Model; log.LogMessage("Security script..."); SqlConnection connection = new SqlConnection(connectionString); connection.Open(); SQLCommand command = new SQLCommand("select cgroup = 'demo' "), connection); object group = command.ExecuteScalar(); if (group != null && group != DBNull.Value){ user.AddSecurityGroup("demo"); }else { user.Error = "User unknown from the database."; } I get ('Test a login' property in the Configuration->Configure Web Security dialog) ERROR: Authentication failed User login name: test
Error is always the same, even if I write SQL query wrong exception "User unknown from the database" is never shown. Query to database is not executed I also do not know where message from log.LogMessage("Security script...") is logged, so I could go step by step and debug what is the problem.
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
Your script is incorrect and does not even compile, here is a sample that should work: Code:@using System.Data
@using System.Data.SqlClient
@using Seal.Helpers
@{
var connectionString = "Server=localhost;Database=Northwind;Trusted_Connection=True";
SecurityUser user = Model;
SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
SqlCommand command = new SqlCommand("select cgroup = 'demo' ", connection);
object group = command.ExecuteScalar();
if (group != null && group != DBNull.Value){
user.AddSecurityGroup("demo");
}else {
user.Error = "User unknown from the database.";
}
}
|
1 user thanked epf for this useful post.
|
|
|
Rank: Member
Groups: Registered
Joined: 6/5/2020(UTC) Posts: 12 Thanks: 4 times
|
|
|
|
|
Rank: Newbie
Groups: Registered
Joined: 9/29/2020(UTC) Posts: 0 Thanks: 2 times
|
Hello,
I have problem with database authentication.
I opened seal server manager, from Configuration=> configure web security I set the security provider to database authentication after that I set the use custom security script to true and I write the code below in the script:
@using System.Data @using System.Data.Common @using System.Data.SqlClient @using Seal.Helpers @{
SecurityUser user = Model; string connectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;Initial Catalog=MyDatabaseName;Data Source='My server's Ip address'"; SqlConnection connection = new SqlConnection(connectionString); connection.Open(); SqlCommand command = new SqlCommand("SELECT dbo.UserGroups.UserGroupName FROM dbo.UserGroups INNER JOIN dbo.Users ON dbo.UserGroups.UserGroupId = dbo.Users.UserGroupId WHERE (dbo.Users.UserName = {0}) AND (dbo.Users.Password = {1}) , Helper.QuoteSingle(user.WebUserName), Helper.QuoteSingle(user.WebPassword)",connection); object group = command.ExecuteScalar(); if (group != null && group != DBNull.Value) { user.AddSecurityGroup((string)group); } else { user.Error = "User unknown from the database."; } }
I have a database in Sql server, when testing it with my user information in the database through Test a login, I got an error :
ERROR: Authentication failed User login name: Admin
Error: Keyword not supported: 'provider'.
what should I do to solve this problem?
Would you please help me with this as soon as possible?
Thanks in advance, Aynaz
|
|
|
|
Rank: Administration
Groups: Administrators
Joined: 12/20/2013(UTC) Posts: 1,209 Thanks: 14 times Was thanked: 206 time(s) in 199 post(s)
|
SqlConnection is the SQLServer driver (not OLEDB), so your connection string must be for SQLServer like: Server=localhost;Database=Northwind;Trusted_Connection=True
|
1 user thanked epf for this useful post.
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.