logo

Warning: The forum is now for consultation only. Please use GitHub Discussions to post any questions or comments.


Welcome Guest ! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
cyracks  
#1 Posted : Tuesday, July 7, 2020 9:21:05 PM(UTC)
cyracks

Rank: Member

Groups: Registered
Joined: 6/5/2020(UTC)
Posts: 12
Slovenia

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 ?
epf  
#2 Posted : Wednesday, July 8, 2020 9:26:29 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

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.
cyracks  
#3 Posted : Wednesday, July 8, 2020 8:02:25 PM(UTC)
cyracks

Rank: Member

Groups: Registered
Joined: 6/5/2020(UTC)
Posts: 12
Slovenia

Thanks: 4 times
For script:
Quote:

// http://csharp.net-inform...ql-server-connection.htm
connectionString = "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.
epf  
#4 Posted : Thursday, July 9, 2020 7:56:23 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

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.";
    }
}
thanks 1 user thanked epf for this useful post.
cyracks on 7/9/2020(UTC)
cyracks  
#5 Posted : Thursday, July 9, 2020 1:48:26 PM(UTC)
cyracks

Rank: Member

Groups: Registered
Joined: 6/5/2020(UTC)
Posts: 12
Slovenia

Thanks: 4 times
Thank you.
ainaz_ama  
#6 Posted : Tuesday, October 20, 2020 8:21:59 AM(UTC)
ainaz_ama

Rank: Newbie

Groups: Registered
Joined: 9/29/2020(UTC)
Posts: 0
Iran (Islamic Republic Of)

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
epf  
#7 Posted : Tuesday, October 20, 2020 10:14:38 AM(UTC)
epf

Rank: Administration

Groups: Administrators
Joined: 12/20/2013(UTC)
Posts: 1,209
Switzerland

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
thanks 1 user thanked epf for this useful post.
ainaz_ama on 10/24/2020(UTC)
Users browsing this topic
Guest
Similar Topics
Help me pleases. How to use Database Authentication with Mysql ? (General Discussions/Other)
by imp 4/29/2019 7:08:56 AM(UTC)
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.