使用长度输入创建随机密码生成

时间:2019-07-11 10:10:06

标签: c# wpf

我正在尝试创建一个随机的密码生成器,该密码生成器允许用户输入他们希望密码使用的字符数,但该字符数必须为6或6+个字符。但是我不确定如何使密码生成器创建与用户输入的长度匹配的密码。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Security.Cryptography;
namespace password_generator1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

    }


    private void Characters_TextChanged(object sender, TextChangedEventArgs e)
    {

    }


    private void Button_Click(object sender, RoutedEventArgs e)
    {

         if (Int32.Parse(characters.Text) >= 6)
       {
           Random passwordGenerator = new Random();
           int range = passwordGenerator.Next(123456789);

         password.Content = range.ToString();

         }

         else { MessageBox.Show("Enter the number of characters for the password", "Invalid characters", MessageBoxButton.OK, MessageBoxImage.Error); }
         }

         }

    }

0 个答案:

没有答案