吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1155|回复: 7
收起左侧

[已解决] 根据这段代码帮忙写一个C#的账号注册,密码找回的程序呗。

 关闭 [复制链接]
a7741200 发表于 2023-10-23 17:13
25吾爱币
[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[17];
			byte[] array2 = new byte[17];
			byte[] bytes = Encoding.ASCII.GetBytes(input);
			for (int i = 0; i < input.Length; i++)
			{
				array[i + 1] = bytes[i];
				array2[i + 1] = array[i + 1];
			}
			long num = (long)((ulong)array[1] + (ulong)array[2] * 256UL + (ulong)array[3] * 65536UL + (ulong)array[4] * 16777216UL);
			long num2 = num * 213119L + 2529077L;
			num2 -= num2 / 4294967296L * 4294967296L;
			num = (long)((ulong)array[5] + (ulong)array[6] * 256UL + (ulong)array[7] * 65536UL + (ulong)array[8] * 16777216UL);
			long num3 = num * 213247L + 2529089L;
			num3 -= num3 / 4294967296L * 4294967296L;
			num = (long)((ulong)array[9] + (ulong)array[10] * 256UL + (ulong)array[11] * 65536UL + (ulong)array[12] * 16777216UL);
			long num4 = num * 213203L + 2529589L;
			num4 -= num4 / 4294967296L * 4294967296L;
			num = (long)((ulong)array[13] + (ulong)array[14] * 256UL + (ulong)array[15] * 65536UL + (ulong)array[16] * 16777216UL);
			long num5 = num * 213821L + 2529997L;
			num5 -= num5 / 4294967296L * 4294967296L;
			array[4] = (byte)(num2 / 16777216L);
			array[3] = (byte)((num2 - (long)((int)array[4] * 16777216)) / 65536L);
			array[2] = (byte)((num2 - (long)((int)array[4] * 16777216) - (long)((int)array[3] * 65536)) / 256L);
			array[1] = (byte)(num2 - (long)((int)array[4] * 16777216) - (long)((int)array[3] * 65536) - (long)((int)array[2] * 256));
			array[8] = (byte)(num3 / 16777216L);
			array[7] = (byte)((num3 - (long)((ulong)array[8] * 16777216UL)) / 65536L);
			array[6] = (byte)((num3 - (long)((ulong)array[8] * 16777216UL) - (long)((int)array[7] * 65536)) / 256L);
			array[5] = (byte)(num3 - (long)((ulong)array[8] * 16777216UL) - (long)((int)array[7] * 65536) - (long)((int)array[6] * 256));
			array[12] = (byte)(num4 / 16777216L);
			array[11] = (byte)((num4 - (long)((ulong)array[12] * 16777216UL)) / 65536L);
			array[10] = (byte)((num4 - (long)((ulong)array[12] * 16777216UL) - (long)((int)array[11] * 65536)) / 256L);
			array[9] = (byte)(num4 - (long)((ulong)array[12] * 16777216UL) - (long)((int)array[11] * 65536) - (long)((int)array[10] * 256));
			array[16] = (byte)(num5 / 16777216L);
			array[15] = (byte)((num5 - (long)((ulong)array[16] * 16777216UL)) / 65536L);
			array[14] = (byte)((num5 - (long)((ulong)array[16] * 16777216UL) - (long)((int)array[15] * 65536)) / 256L);
			array[13] = (byte)(num5 - (long)((ulong)array[16] * 16777216UL) - (long)((int)array[15] * 65536) - (long)((int)array[14] * 256));
			array2[1] = (array2[1] ^ array[1]);
			int j = 1;
			while (j < 16)
			{
				j++;
				array2[j] = (array2[j] ^ array2[j - 1] ^ array[j]);
			}
			j = 0;
			while (j < 16)
			{
				j++;
				bool flag2 = array2[j] == 0;
				if (flag2)
				{
					array2[j] = 102;
				}
			}
			byte[] array3 = new byte[16];
			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[1]);
						sqlCommand.Parameters.AddWithValue("@answer2", new byte[1]);
						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);
						}
					}
				}
			}
		}
	}
}

最佳答案

查看完整内容

[mw_shl_code=csharp,true] 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}$"); ...

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

rsndm 发表于 2023-10-23 17:13
本帖最后由 rsndm 于 2023-10-23 17:33 编辑

[C#] 纯文本查看 复制代码
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[17];
            byte[] array2 = new byte[17];
            byte[] bytes = Encoding.ASCII.GetBytes(input);
            for (int i = 0; i < input.Length; i++)
            {
                array[i + 1] = bytes[i];
                array2[i + 1] = array[i + 1];
            }
            long num = (long)((ulong)array[1] + (ulong)array[2] * 256UL + (ulong)array[3] * 65536UL + (ulong)array[4] * 16777216UL);
            long num2 = num * 213119L + 2529077L;
            num2 -= num2 / 4294967296L * 4294967296L;
            num = (long)((ulong)array[5] + (ulong)array[6] * 256UL + (ulong)array[7] * 65536UL + (ulong)array[8] * 16777216UL);
            long num3 = num * 213247L + 2529089L;
            num3 -= num3 / 4294967296L * 4294967296L;
            num = (long)((ulong)array[9] + (ulong)array[10] * 256UL + (ulong)array[11] * 65536UL + (ulong)array[12] * 16777216UL);
            long num4 = num * 213203L + 2529589L;
            num4 -= num4 / 4294967296L * 4294967296L;
            num = (long)((ulong)array[13] + (ulong)array[14] * 256UL + (ulong)array[15] * 65536UL + (ulong)array[16] * 16777216UL);
            long num5 = num * 213821L + 2529997L;
            num5 -= num5 / 4294967296L * 4294967296L;
            array[4] = (byte)(num2 / 16777216L);
            array[3] = (byte)((num2 - (long)((int)array[4] * 16777216)) / 65536L);
            array[2] = (byte)((num2 - (long)((int)array[4] * 16777216) - (long)((int)array[3] * 65536)) / 256L);
            array[1] = (byte)(num2 - (long)((int)array[4] * 16777216) - (long)((int)array[3] * 65536) - (long)((int)array[2] * 256));
            array[8] = (byte)(num3 / 16777216L);
            array[7] = (byte)((num3 - (long)((ulong)array[8] * 16777216UL)) / 65536L);
            array[6] = (byte)((num3 - (long)((ulong)array[8] * 16777216UL) - (long)((int)array[7] * 65536)) / 256L);
            array[5] = (byte)(num3 - (long)((ulong)array[8] * 16777216UL) - (long)((int)array[7] * 65536) - (long)((int)array[6] * 256));
            array[12] = (byte)(num4 / 16777216L);
            array[11] = (byte)((num4 - (long)((ulong)array[12] * 16777216UL)) / 65536L);
            array[10] = (byte)((num4 - (long)((ulong)array[12] * 16777216UL) - (long)((int)array[11] * 65536)) / 256L);
            array[9] = (byte)(num4 - (long)((ulong)array[12] * 16777216UL) - (long)((int)array[11] * 65536) - (long)((int)array[10] * 256));
            array[16] = (byte)(num5 / 16777216L);
            array[15] = (byte)((num5 - (long)((ulong)array[16] * 16777216UL)) / 65536L);
            array[14] = (byte)((num5 - (long)((ulong)array[16] * 16777216UL) - (long)((int)array[15] * 65536)) / 256L);
            array[13] = (byte)(num5 - (long)((ulong)array[16] * 16777216UL) - (long)((int)array[15] * 65536) - (long)((int)array[14] * 256));
            array2[1] = (byte)(array2[1] ^ array[1]);
            int j = 1;
            while (j < 16)
            {
                j++;
                array2[j] = (byte)(array2[j] ^ array2[j - 1] ^ array[j]);
            }
            j = 0;
            while (j < 16)
            {
                j++;
                if (array2[j] == 0)
                {
                    array2[j] = 102;
                }
            }
            byte[] array3 = new byte[16];
            Buffer.BlockCopy(array2, 1, array3, 0, 16);
            return array3;
        }
    }
}

--------------------------------------------------------------------------------------------------------------------
wpf代码:
[C#] 纯文本查看 复制代码
<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>


Nettos 发表于 2023-10-23 17:19
kll545012 发表于 2023-10-23 17:26
 楼主| a7741200 发表于 2023-10-23 17:27
不知道应该多少!哈哈!随便问问。不是作业。是个账号注册程序内的东西。搞出来就这样了!
kll545012 发表于 2023-10-23 17:50
rsndm 发表于 2023-10-23 17:30
[mw_shl_code=csharp,true]
csharp
using System;

GPT一键生成,哈哈
rsndm 发表于 2023-10-23 17:52
kll545012 发表于 2023-10-23 17:50
GPT一键生成,哈哈

那不然呢,这种非常明确又简单的小需求直接ai搞定了
aakk007 发表于 2023-10-24 09:08
本帖最后由 aakk007 于 2023-10-24 09:10 编辑

[C] 纯文本查看 复制代码
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[17];
            byte[] array2 = new byte[17];
            byte[] bytes = Encoding.ASCII.GetBytes(input);

            // 将密码字符复制到数组中
            for (int i = 0; i < input.Length; i++)
            {
                array[i + 1] = bytes[i];
                array2[i + 1] = array[i + 1];
            }

            long num = (long)((ulong)array[1] + (ulong)array[2] * 256UL + (ulong)array[3] * 65536UL + (ulong)array[4] * 16777216UL);
            long num2 = num * 213119L + 2529077L;
            num2 -= num2 / Magic_3 * Magic_3;

            // 进行额外的密码加密逻辑

            byte[] array3 = new byte[16];
            Buffer.BlockCopy(array2, 1, array3, 0, 16);
            return array3;
        }
    }
}

这种问题随便弄个AI帮你写就行了。以上就是AI写的5秒生成
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 18:56

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表