logo
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: 929
Switzerland

Thanks: 14 times
Was thanked: 155 time(s) in 149 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: 929
Switzerland

Thanks: 14 times
Was thanked: 155 time(s) in 149 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.
Users browsing this topic
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.