{ "cells": [ { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Requirement already satisfied: texttable in /usr/local/lib/python3.7/site-packages (1.6.2)\r\n" ] } ], "source": [ "!pip install texttable" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "from getpass import getpass\n", "import hashlib\n", "from texttable import Texttable" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "LOGO = r\"\"\"\n", "\n", " █████╗███╗ █████╗ ██╗ ██████╗██████████████╗\n", "██╔══██████╗ ██████║ ██║ ██╔═══████╔════██╔════╝\n", "█████████╔████╔████║ █████████║ ████████████████╗\n", "██╔══████║╚██╔╝████║ ██╚════██║ ██╚════██╚════██║\n", "██║ ████║ ╚═╝ ██╚██████╔╝ ╚██████╔██████████████║\n", "╚═╝ ╚═╚═╝ ╚═╝╚═════╝ ╚═════╝╚══════╚══════╝\n", "\n", "\"\"\"" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "def validate_name(name):\n", " for part in name.split():\n", " if not part.isalpha():\n", " return False\n", " return True" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "def take_name_input(prompt):\n", " name = input(prompt)\n", " while not validate_name(name):\n", " print(\"You did not enter the name correctly, please try again!\")\n", " name = input(prompt)\n", "\n", " return name" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [], "source": [ "def print_id(u_info):\n", " table = Texttable()\n", " table.add_rows([[f\"{LOGO} \\n MEMBER - {u_info[0]}\"],\n", " [f\"Slack Username: {u_info[1]}\"],\n", " [f\"MOTHER'S NAME: {u_info[2]}\"],\n", " [f\"FATHER'S NAME: {u_info[3]}\"]\n", " ])\n", " print(table.draw())" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def read_hash(filename):\n", " with open(filename, \"r\") as f:\n", " hash = f.readline()\n", " return hash" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "def authenticate(password):\n", " correct_hash = read_hash(\"hashed_password.txt\")\n", " hashed_password = hashlib.sha256(password.encode('utf-8')).hexdigest()\n", " if hashed_password == correct_hash:\n", " print(\"[INFO] Successfully authenticated!\")\n", " return True\n", " print(\"Authentication failed! You cannot print ID\")\n", " return False" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "def get_user_info():\n", " u_info = []\n", " u_info.append(take_name_input(\"Name of applicant: \"))\n", " u_info.append(input(\"Slack username: \"))\n", " u_info.append(take_name_input(\"Mother's name: \"))\n", " u_info.append(take_name_input(\"Father's name: \"))\n", " return u_info" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "def main():\n", " password = getpass(\"Enter admin password: \")\n", " if authenticate(password):\n", " u_info = get_user_info()\n", " print_id(u_info)" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Enter admin password: ········\n", "[INFO] Successfully authenticated!\n", "Name of applicant: Rahul Jha\n", "Slack username: RJ722\n", "Mother's name: Kumkum Jha\n", "Father's name: Rajeev Kumar Jha\n", "+-------------------------------------------------------+\n", "| |\n", "| |\n", "| █████╗███╗ █████╗ ██╗ ██████╗██████████████╗ |\n", "| ██╔══██████╗ ██████║ ██║ ██╔═══████╔════██╔════╝ |\n", "| █████████╔████╔████║ █████████║ ████████████████╗ |\n", "| ██╔══████║╚██╔╝████║ ██╚════██║ ██╚════██╚════██║ |\n", "| ██║ ████║ ╚═╝ ██╚██████╔╝ ╚██████╔██████████████║ |\n", "| ╚═╝ ╚═╚═╝ ╚═╝╚═════╝ ╚═════╝╚══════╚══════╝ |\n", "| |\n", "| |\n", "| MEMBER - Rahul Jha |\n", "+=======================================================+\n", "| Slack Username: RJ722 |\n", "+-------------------------------------------------------+\n", "| MOTHER'S NAME: Kumkum Jha |\n", "+-------------------------------------------------------+\n", "| FATHER'S NAME: Rajeev Kumar Jha |\n", "+-------------------------------------------------------+\n" ] } ], "source": [ "if __name__ == '__main__':\n", " main()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }