社区
C#
帖子详情
c#.net怎么保存用户名和密码
Gavin_Y
2008-08-02 09:49:17
c#.net怎么保存用户名和密码,点击保存密码下次登陆可以直接进去
...全文
535
13
打赏
收藏
c#.net怎么保存用户名和密码
c#.net怎么保存用户名和密码,点击保存密码下次登陆可以直接进去
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
13 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
umbrella_yang
2008-08-03
打赏
举报
回复
如果是登陆的话,请把用户的个人设置序列化为文件(用户个人配置文件 - Profile)
qjlsharp
2008-08-03
打赏
举报
回复
这东西一般是保存在数据库里比较安全吧
vshirleyzhxl
2008-08-03
打赏
举报
回复
winform可以建数据表来存储用户名和密码信息的表,
然后建议把默认用户用配置文件来记录,在窗体Load时读出来并自动填入,用户登陆时回车就OK了。
下面分别给两个代码吧。
(一)保存用户名和密码到数据库
记得在引用部分加上:
using System.Data.SqlClient;
private void button1_Click(object sender, EventArgs e)
{
string userName = textBox1.Text
string userPswd = textBox2.Text
string constr = "Server=(Local);User Id=Sa;Pwd=;DataBase=HSSN";
SqlConnection con = new SqlConnection(constr);
con.Open();
string instr;
instr = "insert into userinfo(name,pswd) values (" + "'" + userName + "'" + "," + "'" + userPswd + "'" + ")";
SqlCommand cmd = new SqlCommand(instr, con);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
con.Close();
}
(二)下面是一个Iin文件读写的类
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace IniOperator
{
public class INIClass
{
public string inipath;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string def, StringBuilder retVal, int size, string filePath);
public INIClass(string INIPath)
{
inipath = INIPath;
}
///
/// 写入INI文件
///
/// 项目名称(如 [TypeName] )
/// 键
/// 值
public void IniWriteValue(string Section, string Key, string Value)
{
WritePrivateProfileString(Section, Key, Value, this.inipath);
}
///
/// 读出INI文件
///
/// 项目名称(如 [TypeName] )
/// 键
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(500);
int i = GetPrivateProfileString(Section, Key, "", temp, 500, this.inipath);
return temp.ToString();
}
///
/// 验证文件是否存在
///
/// 布尔值
public bool ExistINIFile()
{
return File.Exists(inipath);
}
}
}
(三、)读用上面的类读定Ini文件
private INIClass inic;
inic = new INIClass("写上你的文件名");
//写入
if (inic.ExistINIFile())
{
try
{
inic.IniWriteValue(textBox2.Text, textBox3.Text, textBox4.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//写入ini文件
try
{
textBox4.Text = inic.IniReadValue(textBox2.Text, textBox3.Text);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
Gavin_Y
2008-08-02
打赏
举报
回复
那把数据库路保存到哪里
x55859000
2008-08-02
打赏
举报
回复
........webfrom需要流
winfrom需要数据库...
Gavin_Y
2008-08-02
打赏
举报
回复
那要用到流吗
aimeast
2008-08-02
打赏
举报
回复
存数据库路就可以了。至于数据库是什么格式的,那就随便了。纯文本的也行。
Gavin_Y
2008-08-02
打赏
举报
回复
winform的
wulaiwangyi
2008-08-02
打赏
举报
回复
就是啊楼主你是要winform还是webform,
winform就把登录名和密码写到数据库
webform就写到cookies里面!
cookies方面的这里也许有用
http://www.bitscn.com/dotnet/c/200803/130948.html
aimeast
2008-08-02
打赏
举报
回复
[Quote=引用 1 楼 liuxiuming 的回复:]
用cookie实现吧
[/Quote]你是要winform还是webform啊?
aimeast
2008-08-02
打赏
举报
回复
[Quote=引用 1 楼 liuxiuming 的回复:]
用cookie实现吧
[/Quote]
正解!所有的保存密码都是用的cookies
Gavin_Y
2008-08-02
打赏
举报
回复
详细一点的,cookies我不怎么会用
liuxiuming
2008-08-02
打赏
举报
回复
用cookie实现吧
ASP
.NET
使用Cookie简单实现记住登陆状态功能
页面代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> ...
ASP
.NET
注册界面
上传图片: 1:得到上传文件的文件名:string filename=this.file1.PostedFile.FileName; 2:改名:filename=DateTime.Now.Tick.ToString()+filename.Substring(filename.LastIndexOf("."));//以当前时间命名 3:将文件存在服务器的某个位置file1.PosteFile....
WebForm注册界面
aspx页 http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> http://www.w3.org/1999/xhtml"> .tb { border:1px double green; margin:0 aut
C#
客户端登录Web网站,
保存
用户名
和
密码
首先,添加两个DLL, SHDocVw,mshtml using SHDocVw; using mshtml; //添加以下方法: public void GotoURL(string URL) { //实例化一个IE模型 SHDocVw.InternetExplorer IE = new InternetExplorer(); IE.Visible =
C#
ado
.net
匹配
用户名
和
密码
方式2(分别验证)
//1.获取数据 string name = txtName.Text; string pwd = txtPwd.Text; string pwdMd5 = GetMD5(pwd); //2.比较
用户名
,
用户名
正确,返回
密码
string constr = "data so...
C#
111,128
社区成员
642,536
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章