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

0

新しく生成されたパスワードを AJAX 経由で password-field にロードできます。ユーザーは、パスワード フィールドの横にあるリンクをクリックして、生成されたパスワードの 1 つをフィ​​ールドに入力できます。

もう 1 つのオプションは、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 プラグインには、タスクを簡素化できる多くの機能があります。探しているサンプルについては、こちらを参照してください (フォームの 1 つの要素を更新)

于 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 に答える