这次用java和C#来实现账号登录等功能,因为我感觉它们挺像的,所以就干脆一起来吧。在python中可以通过列表(list)和字典(dict)来存储实现,在java中可以通过ArrayList来实现账号密码的存储和判断,在C#中可以通过泛型List来存储。只要能找到存储账号和密码的途径,剩下的就好办了,话不多说,详细说明请看注释,直接列出代码。

Java源代码如下:

import java.util.ArrayList;
import java.util.Objects;
import java.util.Scanner;//这里我另外创建了一个类来实现
class Account
{private static final Scanner scn = new Scanner(System.in);//设置一个公共的Scanner,不用重复声明定义private static final ArrayList<String> user = new ArrayList<>();       //设置一个user列表来存储账号private static final ArrayList<String> pwd = new ArrayList<>();     //设置一个pwd列表存储密码private static final ArrayList<String> userpwd = new ArrayList<>();    //设置一个列表userpwd来存储账号+密码以及验证账号密码是否匹配protected void Login()    //账号登录{System.out.println("\n----------------- 1.账号登录 ------------------");System.out.print("请输入账号:");String username = scn.nextLine().trim();System.out.print("请输入密码:");String password = scn.nextLine().trim();while (!Objects.equals(username, "") && !Objects.equals(password, "")){if (Objects.equals(username, "")){System.out.println("账号不得为空!\n请输入账号:");username = scn.nextLine().trim();}else if (Objects.equals(password, "")){System.out.print("账号密码不得为空!\n请输入密码:");password = scn.nextLine().trim();}else if (!user.contains(username)){System.out.println("该账号不存在!是否选择注册一个新账号!\n1、是;2、否.");String num = scn.nextLine().trim();if (Objects.equals(num, "1")){Register();}else if (Objects.equals(num, "2")){System.out.println();Main2();}}else if (userpwd.contains(username + password)){System.out.println("账号登录成功!\n");Main2();}else{System.out.println("账号密码错误!");Login();}}}private void Register()     //账号注册{System.out.println("\n----------------- 2.账号注册 ------------------");System.out.print("请输入账号:");String username = scn.nextLine().trim();System.out.print("请输入密码:");String password = scn.nextLine().trim();System.out.print("请确认密码:");String repassword = scn.nextLine().trim();while (!Objects.equals(username, "") && !Objects.equals(password, "")){if (Objects.equals(username, "")){System.out.println("注册账号不得为空!\n请输入账号:");username = scn.nextLine().trim();}else if (Objects.equals(password, "")){System.out.print("账号密码不得为空!\n请输入密码:");password = scn.nextLine().trim();}else if (!Objects.equals(password, repassword) || Objects.equals(repassword, "")){System.out.print("请重新确认密码:");repassword = scn.nextLine().trim();}else if (user.contains(username)){System.out.println("该账号已注册!");Register();}else{System.out.println("账号注册成功!\n");user.add(username);pwd.add(password);userpwd.add(username + password);Main2();}}}private void Change()    //修改账号密码{System.out.println("\n----------------- 3.修改密码 ------------------");System.out.print("请输入账号:");String username = scn.nextLine().trim();System.out.print("请输入旧密码:");String oldpassword = scn.nextLine().trim();System.out.print("请输入新密码:");String newpassword = scn.nextLine().trim();while (!Objects.equals(username, "") && !Objects.equals(oldpassword, "")){if (Objects.equals(username, "")){System.out.print("账号不得为空!\n请输入账号:");username = scn.nextLine().trim();}else if (Objects.equals(oldpassword, "")){System.out.print("密码不得为空!\n请输入旧密码:");oldpassword = scn.nextLine().trim();}else if (Objects.equals(newpassword, "")){System.out.print("密码不得为空!\n请输入新密码:");newpassword = scn.nextLine().trim();}else if (Objects.equals(oldpassword, newpassword)){System.out.print("新旧密码相同!\n请重新确认新密码:");newpassword = scn.nextLine().trim();}else if (!user.contains(username)){System.out.println("账号不存在!");Change();}else if (userpwd.contains(username + oldpassword)){System.out.println("账号密码修改成功!\n");for (int i = 0; i < pwd.size(); i++){if (oldpassword.equals(pwd.get(i))){pwd.remove(pwd.get(i));}}for (int j = 0; j < userpwd.size(); j++){if ((username + oldpassword).equals(userpwd.get(j))){userpwd.remove(userpwd.get(j));}}userpwd.add(username + newpassword);Main2();}else{System.out.println("账号密码错误!");Change();}}}private void Delete()    //账号注销{System.out.println("\n----------------- 4.账号注销 ------------------");System.out.print("请输入账号:");String username = scn.nextLine().trim();System.out.print("请输入密码:");String password = scn.nextLine().trim();while (!Objects.equals(username, "") && !Objects.equals(password, "")){if (Objects.equals(username, "")){System.out.print("账号不得为空!\n请输入账号:");username = scn.nextLine().trim();}else if (Objects.equals(password, "")){System.out.print("密码不得为空!\n请输入密码:");password = scn.nextLine().trim();}else if (!user.contains(username)){System.out.println("账号不存在!");Delete();}else if (userpwd.contains(username + password)){System.out.println("账号注销成功!");for (int i = 0; i < user.size(); i++){if (Objects.equals(username, user.get(i))){user.remove(user.get(i));}}for (int j = 0; j < pwd.size(); j++){if (password.equals(pwd.get(j))){pwd.remove(pwd.get(j));}}for (int k = 0; k < userpwd.size(); k++){if ((username + password).equals(userpwd.get(k))){userpwd.remove(userpwd.get(k));}}Main2();}else{System.out.println("账号密码错误!");Delete();}}}public void Main2()      //主程序选择功能{System.out.println("*********************************************************************");System.out.println(" 1、账号登录;2、账号注册;3、修改密码;4、注销账号;0、退出程序. ");System.out.println("*********************************************************************");System.out.print("请输入选择:");String num = scn.nextLine().trim();while (true){switch (num){case "1" -> Login();case "2" -> Register();case "3" -> Change();case "4" -> Delete();case "0" ->{System.out.println("程序已退出!");System.exit(0);}default ->{System.out.println("请重新选择:");num = scn.nextLine().trim();}}}}
}public class main3
{public static void main(String[] args){Account st = new Account();st.Main2();}
}

运行效果截图

然后是C#源代码:

using System;
using System.Collections.Generic;
using System.Diagnostics;namespace New3
{class Account{private static readonly List<string> user = new List<string>();private static readonly List<string> pwd = new List<string>();private static readonly List<string> userpwd = new List<string>();private void Login(){Console.WriteLine("\n-------------- 1.账号登录 --------------");Console.WriteLine("请输入账号:");string username = Console.ReadLine().Trim();Console.WriteLine("请输入密码:");string password = Console.ReadLine().Trim();while (true){if (username.Equals("")){Console.WriteLine("账号不得为空!\n请输入账号:");username = Console.ReadLine();}else if (password.Equals("")){Console.WriteLine("密码不得为空!请输入密码:");password = Console.ReadLine();}else if (!user.Contains(username)){Console.WriteLine("账号不存在!");YesOrNo();}else if (userpwd.Contains(username + password)){Console.WriteLine("账号登录成功!\n");user.Add(username);pwd.Add(password);userpwd.Add(username + password);Main2();}else{Console.WriteLine("账号密码错误!");Login();}}}private void YesOrNo(){Console.WriteLine("是否选择注册一个新账号?1、是;2、否");string num = Console.ReadLine().Trim();while (true){switch (num){case "1": Register(); break;case "2":{Console.WriteLine(); Main2();}; break;default:{Console.Write("请重新选择:");num = Console.ReadLine().Trim();}; break;}}}private void Register()   //账号注册{Console.WriteLine("\n-------------- 2.账号注册 --------------");Console.WriteLine("请输入新账号:");string username = Console.ReadLine().Trim();Console.WriteLine("请输入密码:");string password = Console.ReadLine().Trim();Console.WriteLine("请确认密码:");string repasword = Console.ReadLine().Trim();while (true){if (username.Equals("")){Console.WriteLine("账号不得为空!\n请输入账号:");username = Console.ReadLine().Trim();}else if (password.Equals("")){Console.WriteLine("密码不得为空!\n请输入密码:");password = Console.ReadLine().Trim();}else if (repasword.Equals("") || !repasword.Equals(password)){Console.WriteLine("请重新确认密码:");repasword = Console.ReadLine().Trim();}else if (user.Contains(username)){Console.WriteLine("该账号已注册!");Register();}else{Console.WriteLine("账号注册成功!\n");user.Add(username);pwd.Add(password);userpwd.Add(username + password);Main2();}}}private void Change()      //修改密码{Console.WriteLine("\n-------------- 3.修改密码 --------------");Console.WriteLine("请输入账号:");string username = Console.ReadLine().Trim();Console.WriteLine("请输入旧密码:");string oldpassword = Console.ReadLine().Trim();Console.WriteLine("请输入旧密码:");string newpassword = Console.ReadLine().Trim();while (true){if (username.Equals("")){Console.WriteLine("账号不得为空!\n请输入账号:");username = Console.ReadLine().Trim();}else if (oldpassword.Equals("")){Console.WriteLine("密码不得为空!请输入密码:");oldpassword = Console.ReadLine().Trim();}else if (newpassword.Equals("") || !newpassword.Equals(oldpassword)){Console.WriteLine("请重新输入新密码:");newpassword = Console.ReadLine().Trim();}else if (!user.Contains(username)){Console.WriteLine("账号不存在!");YesOrNo();}else if (userpwd.Contains(username + oldpassword)){Console.WriteLine("账号密码修改成功!\n");for (int i = 0; i < pwd.Count; i++)     //删除旧密码{if (oldpassword.Equals(pwd[i]))pwd.Remove(pwd[i]);}for (int j = 0; j < userpwd.Count; j++) //删除账号+旧密码{if ((username + oldpassword).Equals(userpwd[j]))userpwd.Remove(userpwd[j]);}userpwd.Add(username + newpassword);Main2();}else{Console.WriteLine("账号密码错误!");Login();}}}private void Delete()     //账号注销{Console.WriteLine("\n-------------- 4.账号注销 --------------");Console.WriteLine("请输入账号:");string username = Console.ReadLine().Trim();Console.WriteLine("请输入旧密码:");string password = Console.ReadLine().Trim();while (true){if (username.Equals("")){Console.WriteLine("账号不得为空!\n请输入账号:");username = Console.ReadLine().Trim();}else if (password.Equals("")){Console.WriteLine("密码不得为空!\n请输入密码:");password = Console.ReadLine().Trim();}else if (!user.Contains(username)){Console.WriteLine("账号不存在!");YesOrNo();}else if (userpwd.Contains(username + password)){Console.WriteLine("账号注销成功!\n");for (int i = 0; i < user.Count; i++){if (username.Equals(user[i]))user.Remove(user[i]);}for (int j = 0; j < pwd.Count; j++){if (password.Equals(pwd[j]))pwd.Remove(pwd[j]);}for (int k = 0; k < userpwd.Count; k++){if ((username + password).Equals(userpwd[k]))userpwd.Remove(userpwd[k]);}Main2();}else{Console.WriteLine("账号密码错误!");Main2();}}}public void Main2(){Console.WriteLine("***********************************************************************");Console.WriteLine("1、账号登录;2、账号注册;3、修改密码;4、账号注销;0、退出程序.");Console.WriteLine("***********************************************************************");Console.Write("请输入选择:");string num = Console.ReadLine().Trim();while (true){switch (num){case "1": Login(); break;case "2": Register(); break;case "3": Change(); break;case "4": Delete(); break;case "0":{Console.WriteLine("程序已退出!");Process.GetCurrentProcess().Kill();}; break;default:{Console.WriteLine("请重新输入选择:");num = Console.ReadLine().Trim();}; break;}}}}class Program{static void Main(){Account st = new Account();st.Main2();Console.ReadKey();}}
}

运行效果截图

以上就是全部代码和说明,对于很多学过Java和C#的小伙伴来说,也很容易理解。由于本人用Java连接SQL Server数据库一直失败,所以就暂时用这种方法来实现;而C#连接SQL数据库的程序代码和窗体登录程序之前我已经写过了,感兴趣的可以去看看。实现账号注册的关键就在于能否找到一个存储途径,剩下的功能代码都是大同小异。除了通过列表来实现,还可以通过文件存储、连接数据库来实现。

JavaC#实现账号登录、账号注册、修改密码、账号注销等功能相关推荐

  1. IDEA版最新SMM整合,根据手机号实现登录/注册/修改密码

    IDEA版最新SMM整合,根据手机号实现登录/注册/修改密码 最近一直在进行springboot的项目,前一阵子项目组接手了一个SSM项目,需要实现手机短信验证的相关功能.于是自己进行了重操,整合了网 ...

  2. 银行管理系统java+mysql8,实现了转账,存钱,取钱,查询账户,开户,登录,自动生成密码账号等功能

    银行管理系统java+mysql8,实现了转账,存钱,取钱,查询账户,开户,登录,自动生成密码账号等功能 文章目录 银行管理系统java+mysql8,实现了转账,存钱,取钱,查询账户,开户,登录,自 ...

  3. c#web窗体登录界面登录注册以及密码找回发送邮箱功能

    c#web窗体登录界面登录注册以及密码找回发送邮箱功能 效果图如下: 1.登录界面aspx代码 <%@ Page Language="C#" AutoEventWireup= ...

  4. 用户第一次登录后要求修改密码

    对于linux管理员而言,一些开发人员在便于排查故障时候需要服务器的登录权限,除了网络权限开放外,第二道防线就是服务器的用户登录权限,,而开发人员的安全意识单薄下,需要进一步保护普通用户的登录权限,因 ...

  5. oracle hr 密码修改,Oracle 11g用户修改密码及加锁解锁功能实例代码

    1.运行 cmd.exe: 2.输入 sqlplus / as sysdba,以系统管理员(sysdba)身份连接数据库,进行数据库管理操作. 3.连接成功后执行 alter user identit ...

  6. java对mysql的简单操作的综合运用——登录+注册+修改密码

    本篇博客是java对mysql的简单操作的综合运用--登录系统.java对mysql的简单操作的综合运用--注册系统.java对mysql的简单操作的综合运用--修改密码系统的整合. 因为使用的是数据 ...

  7. AndroidStudio实现简易android登录注册修改密码页面。

    利用sqlite实现简易登录注册以及修改密码功能. 页面设计 登录页面activity_login.xml <?xml version="1.0" encoding=&quo ...

  8. java项目关联Q登陆,前后端分离项目 — SpringSocial 社交账号登录与注册

    1.前言 今天我们就来讲解下最后一篇如何使用SpringSocial来处理类似微信.QQ社交账号登录自己的平台,也就是大家说的第三方登录,获取社交账户所在平台的用户信息,与自己平台信息做个绑定的操作, ...

  9. 分享一个可以批量换绑百度账号绑定邮箱+批量修改密码的软件

    之前做过贴吧,经常需要入手大量的百度号,因此给账号换绑邮箱(防止扫号).修改密码就成了一件繁重的工作.也曾经因为偷懒,购买之后没有及时换绑邮箱,很快就被不良卖家把号扫回去了,损失惨重! 所以在网上各种 ...

  10. linux锁定账号 让其不能修改密码,passwd - 用于让用户可以更改自己的密码

    补充说明 passwd命令 用于设置用户的认证信息,包括用户密码.密码过期时间等.系统管理者则能用它管理系统用户的密码.只有管理者可以指定用户名称,一般用户只能变更自己的密码. 语法 passwd(选 ...

最新文章

  1. CentOS7下启动Nginx出现Failed to start nginx.service:unit not found
  2. CMU开源:价值百万美元的多目标人体关键点实时检测
  3. js设置ajax执行顺序,2018-03-10fiddler替换js、js的ajax方法执行顺序
  4. ComboBox的数据联动
  5. 重新封装了一下NODE-MONGO 使其成为一个独立的服务.可以直接通过get/post来操作
  6. Get 与 Post 【总结】 (实例:从a.html到b.aspx传值)
  7. 使用visualVM launcher的一些注意事项
  8. git 上下载的项目在本地安装依赖时报错 Could not resolve dependency
  9. Apple Swift编程语言新手教程
  10. Cloud Native Weekly|2019欧洲KubeCon成功闭幕
  11. 数据库大并发操作要考虑死锁和锁的性能问题
  12. 多片段时序数据建模预测实践
  13. 阶段3 1.Mybatis_12.Mybatis注解开发_5 mybatis注解建立实体类属性和数据库表中列的对应关系...
  14. 办公室常用计算机常识,这10个办公必备的电脑小技巧,让你事半功倍
  15. Java聊天室系统的设计与实现(完整源码 sql文件 论文)
  16. 全志A31S(android 4.2/4.4)截屏
  17. jar包扫描工具: gamma
  18. Android 点击屏幕空白处隐藏软键盘
  19. Windows 10 IDM 下载play.kth.se上面的网课视频
  20. jQuery打字练习小游戏代码带音效

热门文章

  1. 如何充实地度过大学四年?
  2. field是什么意思
  3. uart_ops结构体分析之amba_pl011_pops
  4. android tv闹钟_Android 平台有哪些闹钟应用值得推荐?
  5. leetcode1170-比较字符串最小字母出现频次(Map集合存储数组中每个字符串最小元素对应出现频次)
  6. 5篇关于特征嵌入的研究论文推荐
  7. Docker服务正常运行一段时间后突然无法访问问题排查
  8. html语言如何设计锚点,网页html中锚点(描点)定位或书签跳转的实现方法 |
  9. HTML的快乐之旅_全方位的学习html_注意细节——细节决定成败
  10. 【mindgo】 问财+PSY策略