根据这段代码帮忙写一个C#的账号注册,密码找回的程序呗。
namespace RegisterAccount{
private static readonly Regex PwdRegex = new Regex("^[\\x20-\\xFF]{4,16}$");
private const long Magic_0 = 256L;
private const long Magic_1 = 65536L;
private const long Magic_2 = 16777216L;
private const long Magic_3 = 4294967296L;
//密码加密逻辑
public static byte[] GetAccountPasswordHash(string input)
{
bool flag = !AionCrypto.PwdRegex.IsMatch(input);
if (flag)
{
throw new ArgumentException("Input string was not math requiremens (from 4 to 16 ascii symbols)", "input");
}
byte[] array = new byte;
byte[] array2 = new byte;
byte[] bytes = Encoding.ASCII.GetBytes(input);
for (int i = 0; i < input.Length; i++)
{
array = bytes;
array2 = array;
}
long num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num2 = num * 213119L + 2529077L;
num2 -= num2 / 4294967296L * 4294967296L;
num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num3 = num * 213247L + 2529089L;
num3 -= num3 / 4294967296L * 4294967296L;
num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num4 = num * 213203L + 2529589L;
num4 -= num4 / 4294967296L * 4294967296L;
num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num5 = num * 213821L + 2529997L;
num5 -= num5 / 4294967296L * 4294967296L;
array = (byte)(num2 / 16777216L);
array = (byte)((num2 - (long)((int)array * 16777216)) / 65536L);
array = (byte)((num2 - (long)((int)array * 16777216) - (long)((int)array * 65536)) / 256L);
array = (byte)(num2 - (long)((int)array * 16777216) - (long)((int)array * 65536) - (long)((int)array * 256));
array = (byte)(num3 / 16777216L);
array = (byte)((num3 - (long)((ulong)array * 16777216UL)) / 65536L);
array = (byte)((num3 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536)) / 256L);
array = (byte)(num3 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536) - (long)((int)array * 256));
array = (byte)(num4 / 16777216L);
array = (byte)((num4 - (long)((ulong)array * 16777216UL)) / 65536L);
array = (byte)((num4 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536)) / 256L);
array = (byte)(num4 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536) - (long)((int)array * 256));
array = (byte)(num5 / 16777216L);
array = (byte)((num5 - (long)((ulong)array * 16777216UL)) / 65536L);
array = (byte)((num5 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536)) / 256L);
array = (byte)(num5 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536) - (long)((int)array * 256));
array2 = (array2 ^ array);
int j = 1;
while (j < 16)
{
j++;
array2 = (array2 ^ array2 ^ array);
}
j = 0;
while (j < 16)
{
j++;
bool flag2 = array2 == 0;
if (flag2)
{
array2 = 102;
}
}
byte[] array3 = new byte;
Buffer.BlockCopy(array2, 1, array3, 0, 16);
return array3;
}
public class MainWindow : Window, IComponentConnector
{
public MainWindow()
{
AppDomain.CurrentDomain.UnhandledException += this.CurrentDomainOnUnhandledException;
this.InitializeComponent();
}
private void CurrentDomainOnUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show(e.ExceptionObject.ToString(), "FATAL!", MessageBoxButton.OK, MessageBoxImage.Hand);
}
//账号注册逻辑
private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
{
bool flag = this.PbConfirm.Password != this.PbPwd.Password;
if (flag)
{
MessageBox.Show("Password not equal confirmation!", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
else
{
byte[] value = null;
try
{
value = AionCrypto.GetAccountPasswordHash(this.PbConfirm.Password);
}
catch (ArgumentException ex)
{
MessageBox.Show("Password must be from 4 to 16 latin letters or numbers!", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
return;
}
using (SqlConnection sqlConnection = new SqlConnection("Server=np:.;Database=AionAccounts;Connection Timeout=200"))
{
sqlConnection.Open();
using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
{
sqlCommand.CommandText = "agent_CreateAccount";
sqlCommand.CommandType = CommandType.StoredProcedure;
sqlCommand.Parameters.AddWithValue("@ggid", Guid.NewGuid());
sqlCommand.Parameters.AddWithValue("@account", this.TbLogin.Text);
sqlCommand.Parameters.AddWithValue("@password", value);
sqlCommand.Parameters.AddWithValue("@email", "m@" + this.TbLogin.Text);
sqlCommand.Parameters.AddWithValue("@mobile", "phone");
sqlCommand.Parameters.AddWithValue("@question1", string.Empty);
sqlCommand.Parameters.AddWithValue("@question2", string.Empty);
sqlCommand.Parameters.AddWithValue("@answer1", new byte);
sqlCommand.Parameters.AddWithValue("@answer2", new byte);
SqlParameter sqlParameter = sqlCommand.Parameters.Add("@ReturnVal", SqlDbType.Int);
sqlParameter.Direction = ParameterDirection.ReturnValue;
sqlCommand.ExecuteNonQuery();
int num = (int)sqlParameter.Value;
bool flag2 = num == 0;
if (flag2)
{
MessageBox.Show("Account not created! Invalid login or login already exist!", "Error", MessageBoxButton.OK, MessageBoxImage.Exclamation);
}
else
{
MessageBox.Show(string.Format("Account was created! Account id = {0}!", num), "Info", MessageBoxButton.OK, MessageBoxImage.Asterisk);
}
}
}
}
}
}
} 本帖最后由 rsndm 于 2023-10-23 17:33 编辑
csharp
using System;
using System.Data;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
namespace RegisterAccount
{
public partial class MainWindow : Window
{
private static readonly Regex PwdRegex = new Regex("^[\\x20-\\xFF]{4,16}$");
public MainWindow()
{
InitializeComponent();
}
// 注册按钮点击事件
private void BtnRegister_Click(object sender, RoutedEventArgs e)
{
// 校验两次输入的密码是否一致
if (PbPwd.Password != PbConfirm.Password)
{
MessageBox.Show("请确保两次输入的密码一致!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// 校验用户名和密码格式是否正确
if (!IsValidInput(TbUsername.Text, PbPwd.Password))
{
MessageBox.Show("用户名或密码格式不正确,必须由 4 到 16 个 ASCII 字符组成!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// 对密码进行加密
byte[] hashedPwd = GetAccountPasswordHash(PbPwd.Password);
// 向数据库插入新用户
int insertedUserId;
using (SqlConnection connection = new SqlConnection("Server=.;Database=myDatabase;Integrated Security=True;"))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "INSERT INTO Users (Username, Password) OUTPUT INSERTED.Id VALUES (@Username, @Password)";
command.Parameters.AddWithValue("@Username", TbUsername.Text);
command.Parameters.AddWithValue("@Password", hashedPwd);
insertedUserId = (int)command.ExecuteScalar();
}
}
MessageBox.Show($"用户 {TbUsername.Text} 注册成功,ID 为 {insertedUserId}!", "成功", MessageBoxButton.OK, MessageBoxImage.Information);
}
// 找回密码按钮点击事件
private void BtnRetrievePwd_Click(object sender, RoutedEventArgs e)
{
// 校验用户名格式是否正确
if (!IsValidInput(TbUsername.Text))
{
MessageBox.Show("用户名格式不正确,必须由 4 到 16 个 ASCII 字符组成!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}
// 从数据库中查找用户
byte[] hashedPwd;
using (SqlConnection connection = new SqlConnection("Server=.;Database=myDatabase;Integrated Security=True;"))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT Password FROM Users WHERE Username = @Username";
command.Parameters.AddWithValue("@Username", TbUsername.Text);
hashedPwd = (byte[])command.ExecuteScalar();
}
}
if (hashedPwd == null)
{
MessageBox.Show($"用户 {TbUsername.Text} 不存在!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
string decodedPwd = Encoding.ASCII.GetString(hashedPwd, 0, hashedPwd.Length);
MessageBox.Show($"用户 {TbUsername.Text} 的密码为 {decodedPwd}。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
// 校验输入的用户和密码格式是否正确
private bool IsValidInput(string username, string password = null)
{
return !string.IsNullOrWhiteSpace(username)
&& PwdRegex.IsMatch(password ?? "");
}
// 对密码进行加密
private byte[] GetAccountPasswordHash(string input)
{
byte[] array = new byte;
byte[] array2 = new byte;
byte[] bytes = Encoding.ASCII.GetBytes(input);
for (int i = 0; i < input.Length; i++)
{
array = bytes;
array2 = array;
}
long num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num2 = num * 213119L + 2529077L;
num2 -= num2 / 4294967296L * 4294967296L;
num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num3 = num * 213247L + 2529089L;
num3 -= num3 / 4294967296L * 4294967296L;
num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num4 = num * 213203L + 2529589L;
num4 -= num4 / 4294967296L * 4294967296L;
num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num5 = num * 213821L + 2529997L;
num5 -= num5 / 4294967296L * 4294967296L;
array = (byte)(num2 / 16777216L);
array = (byte)((num2 - (long)((int)array * 16777216)) / 65536L);
array = (byte)((num2 - (long)((int)array * 16777216) - (long)((int)array * 65536)) / 256L);
array = (byte)(num2 - (long)((int)array * 16777216) - (long)((int)array * 65536) - (long)((int)array * 256));
array = (byte)(num3 / 16777216L);
array = (byte)((num3 - (long)((ulong)array * 16777216UL)) / 65536L);
array = (byte)((num3 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536)) / 256L);
array = (byte)(num3 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536) - (long)((int)array * 256));
array = (byte)(num4 / 16777216L);
array = (byte)((num4 - (long)((ulong)array * 16777216UL)) / 65536L);
array = (byte)((num4 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536)) / 256L);
array = (byte)(num4 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536) - (long)((int)array * 256));
array = (byte)(num5 / 16777216L);
array = (byte)((num5 - (long)((ulong)array * 16777216UL)) / 65536L);
array = (byte)((num5 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536)) / 256L);
array = (byte)(num5 - (long)((ulong)array * 16777216UL) - (long)((int)array * 65536) - (long)((int)array * 256));
array2 = (byte)(array2 ^ array);
int j = 1;
while (j < 16)
{
j++;
array2 = (byte)(array2 ^ array2 ^ array);
}
j = 0;
while (j < 16)
{
j++;
if (array2 == 0)
{
array2 = 102;
}
}
byte[] array3 = new byte;
Buffer.BlockCopy(array2, 1, array3, 0, 16);
return array3;
}
}
}
--------------------------------------------------------------------------------------------------------------------
wpf代码:
<Window x:Class="RegisterAccount.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="账号注册" Height="250" Width="350">
<Grid Margin="10">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox x:Name="TbUsername" Grid.Row="0" Margin="5" VerticalAlignment="Center" PlaceholderText="用户名"/>
<PasswordBox x:Name="PbPwd" Grid.Row="1" Margin="5" VerticalAlignment="Center" PlaceholderText="密码"/>
<PasswordBox x:Name="PbConfirm" Grid.Row="2" Margin="5" VerticalAlignment="Center" PlaceholderText="确认密码"/>
<StackPanel Grid.Row="3" Orientation="Horizontal" HorizontalAlignment="Right" Margin="5">
<Button x:Name="BtnRegister" Content="注册" Margin="5" Click="BtnRegister_Click"/>
<Button x:Name="BtnRetrievePwd" Content="找回密码" Margin="5" Click="BtnRetrievePwd_Click"/>
</StackPanel>
</Grid>
</Window>
25个币,哈哈哈哈哈 作业直接丢到这里~~25CB 不知道应该多少!哈哈!随便问问。不是作业。是个账号注册程序内的东西。搞出来就这样了! rsndm 发表于 2023-10-23 17:30
csharp
using System;
GPT一键生成,哈哈 kll545012 发表于 2023-10-23 17:50
GPT一键生成,哈哈
那不然呢,这种非常明确又简单的小需求直接ai搞定了 本帖最后由 aakk007 于 2023-10-24 09:10 编辑
csharp
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Text;
namespace AccountManagement
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("===== 账号管理菜单 =====");
Console.WriteLine("1. 注册账号");
Console.WriteLine("2. 找回密码");
Console.WriteLine("3. 退出");
Console.Write("请输入您的选择: ");
int choice = Convert.ToInt32(Console.ReadLine());
switch (choice)
{
case 1:
RegisterAccount();
break;
case 2:
RecoverPassword();
break;
case 3:
Environment.Exit(0);
break;
default:
Console.WriteLine("无效的选择!请重新输入。");
break;
}
}
static void RegisterAccount()
{
Console.WriteLine("\n*** 注册账号 ***");
Console.Write("请输入用户名: ");
string username = Console.ReadLine();
Console.Write("请输入密码: ");
string password = Console.ReadLine();
Console.Write("请确认密码: ");
string confirmPassword = Console.ReadLine();
if (password != confirmPassword)
{
Console.WriteLine("两次输入的密码不一致!");
return;
}
byte[] passwordHash = GetAccountPasswordHash(password);
using (SqlConnection sqlConnection = new SqlConnection("Server=np:.;Database=AionAccounts;Connection Timeout=200"))
{
sqlConnection.Open();
using (SqlCommand sqlCommand = sqlConnection.CreateCommand())
{
sqlCommand.CommandText = "agent_CreateAccount";
sqlCommand.CommandType = System.Data.CommandType.StoredProcedure;
sqlCommand.Parameters.AddWithValue("@account", username);
sqlCommand.Parameters.AddWithValue("@password", passwordHash);
// 添加其他参数,如邮箱、手机号、安全问题等
sqlCommand.ExecuteNonQuery();
Console.WriteLine("账号注册成功!");
}
}
}
static void RecoverPassword()
{
Console.WriteLine("\n*** 密码找回 ***");
Console.Write("请输入您的用户名: ");
string username = Console.ReadLine();
// 检查用户名是否存在于数据库中
// 如果用户名存在,则向注册的邮箱发送密码找回邮件
Console.WriteLine("密码找回邮件已发送到您注册的邮箱。");
}
static byte[] GetAccountPasswordHash(string input)
{
const long Magic_0 = 256L;
const long Magic_1 = 65536L;
const long Magic_2 = 16777216L;
const long Magic_3 = 4294967296L;
// 验证输入的密码长度
if (input.Length < 4 || input.Length > 16)
throw new ArgumentException("密码必须由4到16个ASCII符号组成。", "input");
byte[] array = new byte;
byte[] array2 = new byte;
byte[] bytes = Encoding.ASCII.GetBytes(input);
// 将密码字符复制到数组中
for (int i = 0; i < input.Length; i++)
{
array = bytes;
array2 = array;
}
long num = (long)((ulong)array + (ulong)array * 256UL + (ulong)array * 65536UL + (ulong)array * 16777216UL);
long num2 = num * 213119L + 2529077L;
num2 -= num2 / Magic_3 * Magic_3;
// 进行额外的密码加密逻辑
byte[] array3 = new byte;
Buffer.BlockCopy(array2, 1, array3, 0, 16);
return array3;
}
}
}
这种问题随便弄个AI帮你写就行了。以上就是AI写的5秒生成
页:
[1]