0

我找到了一个密码生成器,并希望有一个允许用户注册的表单,但如果他们希望生成密码,他们可以按生成密码,它会在一个文本输入框中填写密码。

然后我希望他们能够按下注册,它将所有表单数据与手动设置的密码或生成的密码一起发送到表单提交。

有什么想法可以将表单放入有效 HTML 的表单中吗?

我的代码如下:

<form id="register" action="registerprocess.php" method="post">
    <span><strong>Please note all fields are required</strong></span><br /><br />
    <label for="fullname">Full Name: </label><input type="text" id="fullname" name="fullname" required><br />
    <label for="email">Email Address: </label><input type="email" id="email" name="email" required><br /><br />
    <label for="manualpass">User-Defined Password: </label><input type="text" id="manualpass" name="manualpass" required><br />
    <?php

    $f_contents = file("..\sec\possiblewords.txt");
    $word = $f_contents[rand(0, count($f_contents) - 1)];

    function vowelreplacement() {   
        global $word;
        $string = $word;
        $trans = array("a" => "4", "e" => "3", "i" => "1", "o" => "0");

        return strtr($string, $trans);
    }           

    $generatedpassword = vowelreplacement();

    ?>
    <form id="vowelremover" method="post">          
        <label for="generatedpass">Generated Password: </label><input type="text" id="generatedpass" name="generatedpass" value=<?php echo $generatedpassword;?> required><input type="submit" value="Generate Password">
    </form>
    <input type="submit" value="register">
</form>
4

5 回答 5

1

如果您想使用 PHP 生成密码,则必须处理AJAX,然后使用 Javascript 将 Ajax 响应的结果放入您的输入中。

要么也有许多 javascript 密码生成器可以帮助你解决这个问题

于 2013-07-05T08:19:21.863 回答
0

您可以通过 AJAX 将新生成的密码加载到密码字段中。用户可以单击密码字段旁边的链接以使用您生成的密码之一填写该字段。

另一种选择是使用 javascript 生成密码并将其放入字段中。这样你就不需要生成 php-script 并且 js 将被简化。

于 2013-07-05T08:17:14.190 回答
0

实现 jQuery 插件,然后执行以下操作:

ajax.php(例如在服务器 test.com 上)

<?php

$f_contents = file("..\sec\possiblewords.txt");
$word = $f_contents[rand(0, count($f_contents) - 1)];

function vowelreplacement() {   
    global $word;
    $string = $word;
    $trans = array("a" => "4", "e" => "3", "i" => "1", "o" => "0");

    return strtr($string, $trans);
}           

echo vowelreplacement();

form.php(放置表单的 php 文件)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>

<form id="register" action="registerprocess.php" method="post">
    <span><strong>Please note all fields are required</strong></span><br /><br />
    <label for="fullname">Full Name: </label><input type="text" id="fullname" name="fullname" required><br />
    <label for="email">Email Address: </label><input type="email" id="email" name="email" required><br /><br />
    <label for="manualpass">User-Defined Password: </label><input type="text" id="manualpass" name="manualpass" required><br />

    <form id="vowelremover" method="post">          
        <label for="generatedpass">Generated Password: </label><input type="text" id="generatedpass" name="generatedpass" value=<?php echo $generatedpassword;?> required><input type="submit" value="Generate Password">
    </form>
    <input type="submit" value="register">
</form>

<script type="text/javascript">

$(function() {

    $("#vowelremover").submit(function() {

        $("#generatedpass").load("http://test.com/ajax.php");

        return false;
    });
});

</script>
于 2013-07-05T08:27:36.627 回答
-1

jquery 插件具有许多可以简化您的任务的功能。有关您要查找的示例,请参见此处(刷新表单的一个元素)

于 2013-07-05T08:22:49.647 回答
-4

我为随机密码生成器提供了更好且功能齐全的 VB 代码。这是我自己用 VB Express 编写的程序。用户可以选择密码的长度,并从大写、小写、数字或特殊字符中进行选择。您可以生成 8 到 25 个字符的无限密码。这是下载完整程序的代码和.RAR文件。最好的是......它是免费的!

\\\======================================================================\\\
Option Explicit On
'---------------------------------------------------------------------
'---------------------------------------------------------------------
'---------------------- Password Generator ® -------------------------
'---------------------- Author: Chirag Patel -------------------------
'---------------------- Current Version: 1.x -------------------------
'---------------------- Date: August, 14, 2015 -----------------------
'---------------------- License: FREE License Program ----------------
'---------------------------------------------------------------------
'---------------------------------------------------------------------

Public Class frmPassGen
    'Declearing main intiger which will hold password
    Dim Letters As New List(Of Integer)

Public Function Info()
    'This button provide information about author 
    Dim Infor As String

    Infor = MsgBox("Program:  Password Generator ®" & _
                  vbCrLf & "---------------------------------" & _
                  vbCrLf & "Version: 1.0" & _
                  vbCrLf & "Programmer: Chirag Patel" & _
                  vbCrLf & " " & _
                  vbCrLf & "Legal Verbiage" & _
                  vbCrLf & "-----------------" & _
                  vbCrLf & "This program is FREE License program." & _
                  vbCrLf & " " & _
                  vbCrLf & "Thank you." & _
                  vbCrLf & "Chirag Patel", MsgBoxStyle.Information, "Password Generator")
    cmbLength.Focus()
End Function

Public Function Clear()
    On Error Resume Next
    'Clears ALL
    cmbLength.Text = "000"
    cmbLength.Focus()
    txtPassword.Text = "... Your Password ..."
    chkUpper.Checked = False
    chkLower.Checked = False
    chkNumber.Checked = False
    chkSpecial.Checked = False
    txtLPass.Text = ""
    cmbNpass.Text = "000"
End Function

Public Function Upper()
    'Add ASCII Codes For Upper Case Letters
    For i As Integer = 65 To 90
        Letters.Add(i)
    Next
End Function

Public Function Lower()
    'Add ASCII Codes For Lower Case Letters
    For i As Integer = 97 To 122
        Letters.Add(i)
    Next
End Function

Public Function Numbers()
    'Add ASCII Codes For Numbers
    For i As Integer = 48 To 57
        Letters.Add(i)
    Next
End Function

Public Function Special()
    'Add ASCII Codes For Special Characters
    For i As Integer = 33 To 47
        Letters.Add(i)
    Next
End Function

Public Function uRemove()
    Dim rRnd As New Random
    Dim rSB As New System.Text.StringBuilder
    Dim trPass As Integer
    'Remove ASCII code for Upper case letters
    For i As Integer = 65 To 90
        Letters.Remove(i)
    Next
    'Remove ASCII Codes For Lower Case Letters
    For i As Integer = 97 To 122
        Letters.Remove(i)
    Next
    'Remove ASCII Codes For Numbers
    For i As Integer = 48 To 57
        Letters.Remove(i)
    Next
    'Remove ASCII Codes For Special Characters
    For i As Integer = 33 To 47
        Letters.Remove(i)
    Next
    'Remove cache
    For count As Integer = -1 To Val(cmbLength.Text)

        trPass = rRnd.Next(0, Letters.Count)
        rSB.Append(Chr(Letters(trPass)))

    Next
    txtPassword.Text = rSB.ToString
End Function

Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
    On Error Resume Next
    'Exit Program
    Me.Close()
    End
End Sub

Private Sub txtPassword_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtPassword.KeyDown
    On Error Resume Next
    'Doesn't allow to change password
    txtPassword.Text = ""
    MsgBox("You cannot change password here.", MsgBoxStyle.Information, "Password Generator")
    txtPassword.Text = "... Your Password ..."
    cmbLength.Text = "000"
    cmbNpass.Text = "000"
    cmbLength.Focus()
End Sub

Private Sub frmPassGen_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    On Error Resume Next
    'Default Settings
    cmbLength.Text = "000"
    cmbNpass.Text = "000"
    cmdOK.Enabled = False
    txtPassword.Text = "... Your Password ..."
    cmbLength.Focus()
    lbltTime.Text = TimeOfDay
    Me.Text = "Password Generator -  " & Format(Date.Now, "dddd, MM-dd-yyyy")
End Sub

Private Sub cmbLength_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbLength.SelectedIndexChanged
    On Error Resume Next
    'Enable Generate Button
    If cmbLength.Text = "000" Then
        cmdOK.Enabled = False
    Else
        cmdOK.Enabled = True
    End If
End Sub

Private Sub cmdInfo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdInfo.Click
    On Error Resume Next
    'Display Program Info
    Call Info()
End Sub
Private Sub cmdOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdOK.Click
    On Error Resume Next
    For i As Integer = 0 To Val(cmbNpass.Text)              'Number of passwords need to generate

        'Disabled OK (Generate) Button when no options are selected
        If chkLower.Checked = False And chkNumber.Checked = False And chkSpecial.Checked = False And chkUpper.Checked = False Then
            MsgBox("Please select at list one of the four options to generate new random password.", MsgBoxStyle.Information, "...Password Generator")
            cmbLength.Focus()
            cmdOK.Enabled = False
        End If

        'Decleration of Variables 
        Dim Rnd As New Random                           ' Generates Random Strings
        Dim SB As New System.Text.StringBuilder         ' Bings the String generated by Rnd
        Dim tPass As Integer                            ' Temp Variable to hold the generated string in temp continer

        'Condition...
        If cmbLength.Text = "000" And cmbNpass.Text = "000" Then
            Beep()
            MsgBox("You must select the length and numbers password.", MsgBoxStyle.Information, "Password Generator")
        Else
            cmdOK.Enabled = True
        End If
        'Creating password string...

        For count As Integer = 1 To Val(cmbLength.Text)     'Length of password

            tPass = Rnd.Next(0, Letters.Count)
            SB.Append(Chr(Letters(tPass)))
            Resume
        Next
        If Val(i) = 1 Then                                      'One Password Generated
            txtPassword.Text = SB.ToString
        Else
            txtPassword.Text = SB.ToString                     'More Password Generated
            txtLPass.Text += txtPassword.Text & vbNewLine
        End If
    Next


    'Disabled OK (Generate) Button when no options are selected
    If chkLower.Checked = False And chkNumber.Checked = False And chkSpecial.Checked = False And chkUpper.Checked = False Then
        cmbLength.Text = "000" And cmbNpass.Text = "000"
    End If
End Sub

Private Sub cmbLength_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cmbLength.KeyDown
    On Error Resume Next
    'Doesn't allow users to alter the value in selection (drop down box)
    cmbLength.Text = ""
    cmbLength.Text = "000"
    MsgBox("Sorry, you cannot alter the value in this area.", MsgBoxStyle.Information, "Password Generator")
End Sub

Private Sub chkUpper_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkUpper.CheckedChanged
    If chkUpper.Checked = True Then
        Call Upper()
    Else
        'Remove ASCII code for Upper case letters
        For i As Integer = 65 To 90
            Letters.Remove(i)
        Next
    End If
End Sub

Private Sub chkLower_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLower.CheckedChanged
    If chkLower.Checked = True Then
        Call Lower()
    Else
        'Remove ASCII Codes For Lower Case Letters
        For i As Integer = 97 To 122
            Letters.Remove(i)
        Next
    End If
End Sub

Private Sub chkNumber_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkNumber.CheckedChanged
    If chkNumber.Checked = True Then
        Call Numbers()
    Else
        'Remove ASCII Codes For Numbers
        For i As Integer = 48 To 57
            Letters.Remove(i)
        Next
    End If
End Sub

Private Sub chkSpecial_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkSpecial.CheckedChanged
    On Error Resume Next
    'Checks if the Special Checkbox is checked
    If chkSpecial.Checked = True Then
        Call Special()
    Else
        'Remove ASCII Codes For Special Characters
        For i As Integer = 33 To 47
            Letters.Remove(i)
        Next
    End If
End Sub

Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
    On Error Resume Next
    'Call Clear
    Call Clear()
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    lbltTime.Text = TimeOfDay
End Sub

Private Sub txtLPass_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtLPass.KeyDown
    On Error Resume Next
    'Doesn't allow Edit...
    MsgBox("You cannot alter the password here.", MsgBoxStyle.Information, "Password Generator")
    Call Clear()
End Sub

Private Sub cmbNpass_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbNpass.SelectedIndexChanged
    On Error Resume Next
    'Enable Generate Button
    If cmbNpass.Text = "000" Then
        cmdOK.Enabled = False
    Else
        cmdOK.Enabled = True
    End If
End Sub

结束类

于 2016-07-09T17:26:46.713 回答