I'm developing a DLL project that make transactions with a database server, the only problem is that must be an idependent DLL, and it needs to ask for a login screen if not found any previous information. This login screen needs to be written in C#, just lik开发者_如何学Goe an Windows Application.
Any ideas would be very apreciatted.
Thanks in advance
This isn't the sort of thing you would typically put into a dll. A login screen would be dependent on the implementing UI. You would be better of creating a data access class that implements an interface that has the login credentials required implemented as properties. This allows any consuming application (web, winforms, wpf, whatever) to create a login screen or pass direct credentials to the data class:
public interface IMyDataInterface
{
string loginUser { get; set; }
string loginPW { get; set; }
}
public class MyDataLayer : IMyDataInterface
{
public MyDataLayer(string login, string pw)
{
loginUser = login;
loginPW = pw;
}
}
Using the interface faithfully guarantees that any exposed datalayer has the same implementation basics for consuming applications.
Edit to reflect more secure method: (idea by @Chris)
using System.Net;
public interface IMyDataInterface
{
NetworkCredential credentials { get; set; }
}
public class MyDataLayer : IMyDataInterface
{
public MyDataLayer(NetworkCredential loginInfo)
{
credentials = loginInfo;
}
}
The constructor can be overloaded to include multiple methods of providing the credentials, but the SecureString class should be used to contain the password in all calls.
精彩评论