开发者

C# Change string in dll through exe

I'm new here and quite new to C# as well. Been playing around a bit and got a hang of the basic, but now I have digged a bit to deep for my level of skill to follow.

I have created a program where you have to log in and to that I have created a dll in the same project that contain all the data. I have done this because I want to be able to alter the data through the program. There are ftp-functions and simular involed and the program is for several different users, so I can't save the same password and data for everyone.

I have no problem calling the data from the dll to get the password, but I also want to change that password in the dll through a settings-form. How can I开发者_JS百科 do this?

Part of the main program:

    public static string updatePass()
    {

    }

    public void apply_Click(object sender, EventArgs e)
    {
        string newPass = newPassField.Text;
        string rePass = rePassField.Text;

        int pass_value = newPass.CompareTo(rePass);
        if (pass_value == 0)
        {

        }
        else
            MessageBox.Show("Error: The passwords does not match!");
    }

Part of the dll where the password is:

    public static string passData(string password = null)
    {
        return (password);
    }


Generally, you don't. DLL is code, not data. To do what you want, you really should be storing your data somewhere (database, flat file, whatever) and then using your code to read/write it. and of course for passwords you want to make sure they're securely hashed.


Honestly, your best bet is going to be avoiding storing the password in the DLL, as there is no persistent storage of non-static data within a DLL file. So you can store constants in DLLs, but not passwords. Now, if you want, you can store the user's password in a user specific registry key (encrypted I would hope :)) and then access that from the DLL, and that would let you have the illusion of storing the password in the DLL and get you kind of where you want to go.

You can also look (if you're using 3.5+) into using C#'s internal settings mechanism - this would let you transparently write the data from the winform then read it from the DLL without having to worry about -WHERE- it's stored.

Good luck!


Use a settings file. visual studio already supports this. Also never store plain text passwords, store only a password hash.


You should be aware that any passwords you have in code can be found relatively easily by anyone who has access to the dll using a tool like reflector.

If you do pass the credentials along with the dll make sure you secure them properly. If you are going to store them in a config file, this article goes over a good method of encrypting them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜