如何使用VB加密在登录表单中输入的密码? [英] How to encrypt password entered in login form using VB?

查看:145
本文介绍了如何使用VB加密在登录表单中输入的密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的登录表单中,用户需要在相对文本框中输入用户名和密码,然后按按钮LOGIN。用户名和密码已经保存到文本文件中,每次用户尝试输入用户名时,他输入的密码将与保存到文本文件中的用户名和密码相匹配,如果匹配,则用户将是允许访问。我现在希望能够加密在文本框中输入的密码,我尝试在线查看,但我没有找到任何帮助。有谁有想法吗?在此先感谢。



我尝试过:



In my Login form the user needs to input the username and password in the relative textboxes and then press the button LOGIN. The username and password are already saved into a text file, every time the user tries to enter the username and password entered by him will be matched with the ones saved into the text file and if they do match, only then, the user would be allowed access. I now want to be able to encrypt the password that's been entered in the textbox, I have tried looking online but I've not found any help. Does anyone have any idea? Thanks in advance.

What I have tried:

Dim intnum1 As Integer

    Dim str2 As String

    Dim icounter As Integer

 

 

    Private Sub cmdCipher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCipher.Click

        For icounter = 1 To Len(txtCTC.Text)

            intnum1 = Asc(Mid(txtCTC.Text, icounter, 1)) 'Converts the letter to a ANSI number

            intnum1 = intnum1 + 3 'Adds three to the ANSI number

            str2 = Chr(intnum1)   'Converts the ANSI number back to a letter

 

            txtCipher.Text = txtCipher.Text & str2 'Adds the ciphered letter to the end of whatever was previously in the textbox

        Next

    End Sub

 

 

    Private Sub cmdDecipher_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDecipher.Click

        For icounter = 1 To Len(txtCipher.Text)

            intnum1 = Asc(Mid(txtCipher.Text, icounter, 1)) 'Converts the letter to a ANSI number

            intnum1 = intnum1 - 3 'Adds three to the ANSI number

            str2 = Chr(intnum1)   'Converts the ANSI number back to a letter

 

            lbldecrypt.Text = lbldecrypt.Text & str2 'Adds the ciphered letter to the end of whatever was previously in the textbox

        Next

    End Sub

End Class

推荐答案

不加密;哈希吧。



安全密码验证简单说明 [ ^ ]

Salted Password Hashing - 正确行事 [ ^ ]



为每个密码生成一个随机盐;将其附加(或前置)到密码字节;然后生成密码的单向散列。将salt和hash存储在您的文件中。



当您需要验证密码时,请从文件中为用户加载salt和hash。将salt与输入密码的字节组合在一起,方式与之前完全相同。生成组合值的单向散列,并将其与从文件加载的散列进行比较。
Don't encrypt it; hash it.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

Generate a random salt for each password; append (or prepend) it to the password bytes; then generate a one-way hash of the password. Store the salt and the hash in your file.

When you need to validate the password, load the salt and the hash from the file for the user. Combine the salt with the bytes of the entered password in exactly the same way as before. Generate the one-way hash of the combined value, and compare it to the hash loaded from the file.


这篇关于如何使用VB加密在登录表单中输入的密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆