国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

.NET中帶有口令加密的注冊頁面

2024-07-10 12:58:36
字體:
供稿:網(wǎng)友

在asp.net中提供了加密的功能。名字空間system.web.security中包含了類formsauthentication,其中有一個方法hashpasswordforstoringinconfigfile。這個方法可以將用戶提供的字符變成亂碼,然后存儲起來。注意此方法是不能繼承的。
下面的代碼就是在做注冊頁面時將數(shù)據(jù)加密后存儲到數(shù)據(jù)庫的過程
imports system.web.security
imports system.data
imports system.data.sqlclient  '////////所需要的名稱空間

private sub button1_click(byval sender as system.object, byval e as system.eventargs) handles button1.click
        dim passformate as string
        '///////////////encryptpassword調(diào)用函數(shù)
        passformate = encryptpassword(uid.text, "md5")   '//////////或者是encryptpassword(uid.text, "sha1")
        'textbox2.text = encryptpassword(uid.text, "md5")
        'textbox3.text = encryptpassword(uid.text, "sha1")
        '///////////這些大家自己試驗吧
        'textbox4.text = formsauthentication.formscookiename
        'textbox5.text = formsauthentication.formscookiepath
        'textbox6.text = formsauthentication.getredirecturl(uid.text, true)
        'formsauthentication.setauthcookie(uid.text, true)

        dim sql as string = "insert into pwd(uid,pwd) values(@uid,@pwd)"
        dim comm as sqlcommand = new sqlcommand(sql, conn)
        conn.open()
        comm.parameters.add(new sqlparameter("@uid", sqldbtype.char, 16))
        comm.parameters("@uid").value = uid.text
        comm.parameters.add(new sqlparameter("@pwd", sqldbtype.char, 16))
        comm.parameters("@pwd").value = passformate
        comm.executenonquery()
        
    end sub

    '////////////////定義加密函數(shù),可以隨時調(diào)用。
    function encryptpassword(byval password as string, byval passwordformate as string)
        if passwordformate = "sha1" then
            encryptpassword = formsauthentication.hashpasswordforstoringinconfigfile(password, "sha1")
        elseif passwordformate = "md5" then
            encryptpassword = formsauthentication.hashpasswordforstoringinconfigfile(password, "md5")
        else
            encryptpassword = ""
        end if

    end function
至于用戶的驗證也是一樣的思路了。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 崇明县| 阳信县| 麻城市| 托克逊县| 大城县| 沿河| 鄂伦春自治旗| 菏泽市| 承德县| 廉江市| 绍兴市| 克拉玛依市| 赤峰市| 登封市| 安龙县| 二连浩特市| 青河县| 卓资县| 凤山市| 巴里| 治县。| 海丰县| 湖北省| 襄城县| 嘉荫县| 屏东县| 菏泽市| 凤庆县| 磐安县| 时尚| 临清市| 伊宁市| 嫩江县| 德保县| 阳曲县| 博乐市| 曲阜市| 海丰县| 黄龙县| 莱阳市| 隆德县|