How can I prompt for a username and password for a connection string?

Jeff Brady

I have a C# Winforms app that I'm porting over to ASP.NET. Everything works, but the connection to my Universe database currently uses my personal name and password. Instead, I'd like to get the user's name and password.

In web.config added the following to connectionStrings:

<add name="U2Connection" connectionString="Database=MY_DB;User ID=myuserid;
Password=mypassword;Server=MY_SERVER;ServerType=UNIVERSE;AccessMode=Native;
RpcServiceType=uvcs" providerName="U2.Data.Client" />

and in my class, I have the following:

public static U2Connection GetU2ConWebConfig()
{
        string conn_str = ConfigurationManager.ConnectionStrings["U2Connection"].ToString();
        U2Connection con = new U2Connection();
        con.ConnectionString = conn_str;
        con.Open();

        return con;
}

How can I prompt the current user for their Universe username/password and pass it to the connection string? I know I could make 2 textboxes on the .cshtml page and pass it along with the rest of the form data, but is there a better or more secure way?

Denys Wessels

You could change your connection string like this:

<add name="U2Connection" connectionString="Database=MY_DB;User ID={0};Password={1};Server=MY_SERVER;ServerType=UNIVERSE;AccessMode=Native;RpcServiceType=uvcs" providerName="U2.Data.Client" />

Then you can pass through the user name and password to it using String.Format():

string userName = "User";
string password = "Password";
string connectionString = String.Format(ConfigurationManager.ConnectionStrings["U2Connection"].ConnectionString, userName, password);

Regarding security - I would suggest using HTTPS for your website or at least for the page where the user has to enter their credentials.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

In pg_restore, how can you use a postgres connection string to specify the host/database/username/password?

Regex that can extract a username and password from a postgresql connection string?

How can I save username and password in Git?

How do you 'escape' a username:password pair in a connection string?

How to hide MySQL Connection String- Username and Password on GitHub (Java)

How can I get LOGON_USER info from windows auth without having the username password prompt appear?

Dynamically Provide Username and password to Connection String

RODBC - connection string add username and password

Can username and password be passed in connection url for cassandra

Prompt for password but not username?

Given a linux username and a password how can I test if it is a valid account?

How can i change activity using login (username and password) ,button ?

How can I protect MySQL username and password from decompiling?

how can i set username and password for basic http authentication?

How can I allow a client to log into a Samba share with a username and password?

How can I send username and password to an express server with ajax?

how can i make a username and password test method that doesnt overlap?

How can I use auto username and password save in html?

How can I get username and password from SharedPreferences in Android?

How do I send a username and password to git's credential user prompt from my powershell script?

How can I get browser to prompt to save password?

How can I CTRL^C out of a password prompt?

How can I check GMail messages with prompt for password from a script?

How can i get the password of oracle user instance from oracle connection string using C#?

How to get Python MYSQL connection username and password?

How to setup connection to HIVE using PySpark and SparkSession (How do I add username and password)?

How can i use spring security to authenticate users with an Id and password instead of username and password

How to force git to prompt me for username + password on clone request

mysql command line: How to make mysql to prompt for username and password?