新用户可以使用已经存在的用户名(文本文件问题)创建一个帐户

发布于 2025-01-28 17:20:50 字数 539 浏览 2 评论 0原文

我是Python的新手,并且正在尝试创建可靠的帐户创建和存储程序。当用户想创建一个新的用户名时,读取用户名_Storage文件以查看它是否已经存在于另一个帐户。

# Enter and check username
            new_user = input("Username: ")
            if new_user in username_storage:
                print("Sorry, that username is already taken.\n")
            else:
                break

问题是,每当用户尝试使用现有用户名的一部分创建新帐户时,该程序就不允许它,因为它会注册新用户名在预制用户名中。

例如,如果“ William”是USERNAME_STOREAGE文本文件中的现有用户名,则不允许新的用户名“ Will”或“ Liam”,因为这些名称在“ William”中。

感谢任何能够回答这个问题的人;如果我还没有足够清楚地解释我的问题,请告诉我!

I'm relatively new to python and am trying to create a reliable account creation and storage program. When the user wants to create a new username, the username_storage file is read to see if it already exists for another account.

# Enter and check username
            new_user = input("Username: ")
            if new_user in username_storage:
                print("Sorry, that username is already taken.\n")
            else:
                break

The problem is that whenever the user tries to create a new account using part of an existing username, the program does not allow it because it registers that the new username is inside a pre-made username.

e.g. if "william" is an existing username in the username_storage text file, it doesn't allow the new username "will" or "liam" because those names are inside "william".

Thanks to anyone who may be able to answer this question; if I haven't explained my problem clearly enough, please let me know!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

握住我的手 2025-02-04 17:20:50
usernames = username_storage.split()
print(new_user in usernames)

假设您在用户名中没有空间,会做您想做的事

usernames = username_storage.split()
print(new_user in usernames)

would do what you want assuming you cant have spaces in the username

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文