社区
C#
帖子详情
c#.net怎么保存用户名和密码
Gavin_Y
2008-08-02 09:49:17
c#.net怎么保存用户名和密码,点击保存密码下次登陆可以直接进去
...全文
472
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
中登录时记住
用户名
和
密码
使用ASP
.NET
建站时,登录模块中常用的技术,解决了客户重复输入的
用户名
和
密码
比较麻烦的问题,实用性很强。
C#
用户名
密码
登入程序
C#
中连接 oracle 数据库,实现类似于qq的
用户名
密码
登入的功能,文档里面有详细的步骤和注释;
C#
、
.NET
读取AD域里
用户名
或组
C#
、
.NET
读取AD域里
用户名
或组
C#
、
.NET
读取AD域里
用户名
或组
C#
、
.NET
读取AD域里
用户名
或组
c#
登录窗体,判断
用户名
、
密码
,成功后打开主窗体,允许输入3次,不成功退出
打开登录窗体,输入
用户名
、
密码
成功后打开主窗体。
用户名
Admin,
密码
nopassword. 参考http://blog.csdn
.net
/Knight94/archive/2006/04/06/652394.aspx 的文章实现。
c#
.net
系统网站
一个系统网站,其中系统管理员的
用户名
和
密码
都是admin
C#
110,534
社区成员
642,576
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章