C# 通过exe更改dll中的字符串
我是新来的,对 C# 也很陌生。经过一番尝试并掌握了基础知识,但现在我已经深入挖掘了一些我可以遵循的技能水平。
我创建了一个程序,您必须登录该程序,并且我在同一项目中创建了一个包含所有数据的 dll。我这样做是因为我希望能够通过程序更改数据。有ftp功能和模拟功能,并且该程序适用于多个不同的用户,因此我无法为每个人保存相同的密码和数据。
我可以毫无问题地从 dll 中调用数据来获取密码,但我还想通过设置表单更改 dll 中的密码。我该怎么做?
主程序部分:
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!");
}
dll 部分,其中密码为:
public static string passData(string password = null)
{
return (password);
}
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 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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
一般来说,你不会。 DLL 是代码,而不是数据。为了做你想做的事,你真的应该将数据存储在某个地方(数据库、平面文件等),然后使用你的代码来读/写它。当然,对于密码,您需要确保它们经过安全散列处理。
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.
老实说,最好的选择是避免将密码存储在 DLL 中,因为 DLL 文件中没有非静态数据的持久存储。因此,您可以在 DLL 中存储常量,但不能存储密码。现在,如果您愿意,您可以将用户的密码存储在用户特定的注册表项中(我希望是加密的:)),然后从 DLL 访问该密码,这会让您产生将密码存储在 DLL 中的错觉,并且带你去你想去的地方。
您还可以查看(如果您使用的是 3.5+)使用 C# 的 内部设置机制 - 这将让您透明地从 winform 写入数据,然后从 DLL 读取数据,而不必担心它存储在何处。
祝你好运!
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!
使用设置文件。 Visual Studio 已经支持这一点。也不要存储纯文本密码,仅存储密码哈希。
Use a settings file. visual studio already supports this. Also never store plain text passwords, store only a password hash.
您应该意识到,任何有权访问 dll 的人都可以使用 反射器。
如果您确实将凭据与 dll 一起传递,请确保正确保护它们。如果要将它们存储在配置文件中,这篇文章介绍了一种加密它们的好方法。
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.