{"id":26011,"date":"2022-12-15T00:26:33","date_gmt":"2022-12-14T18:56:33","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/"},"modified":"2022-12-15T00:26:33","modified_gmt":"2022-12-14T18:56:33","slug":"solved-find-password-by-username","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/","title":{"rendered":"[Solved] Find password by username"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-32784687\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"32784687\" data-parentid=\"32779786\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>I am supposing your csv will be like this:<\/p>\n<pre><code>user1, hash_pass_u1\nuser2, hash_pass_u2\nuser3, hash_pass_u3\n...\n<\/code><\/pre>\n<p>Just one note before the solution. You are importing the CSV module of Python and you did not use it in your code, such a silly import, just use it.<\/p>\n<p>The solution is simple <\/p>\n<pre class=\"lang-python prettyprint-override\"><code>import csv\n\nfile=\"yourcsv.csv\"\nfound = False\nusername = input('Write your username: ')\npassword_csv = None\nwith open(file, newline=\"\") as csvfile:\n   reader = csv.reader(csvfile, delimiter=\",\")\n   for row in reader:\n      # row[0] is the first element, the username and row[1] the hash of the password\n      if row[0] == username:\n         password_csv = row[1]\n         found = True\n         break\nif not found:\n   print('The username is not in our DB.')\n\nwhile True:\n   passw = input('Let me your password: ')\n   hash_passw = your_method_to_get_the_hash(passw)\n   if hash_passw == password_csv:\n      print('Congrats, you are logged.')\n      break\n   else:\n      print('Wrong password dude, try again.') \n<\/code><\/pre>\n<p>In this way you only read the file once and you will use the CSV Module.<\/p>\n<p>I&#8217;m supposing the format of your CSV if it is another format is easy to change the implementation of this solution. If you need some help with the CSV Module the documentation is here, for <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.python.org\/2\/library\/csv.html\">python2<\/a> and <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/csv.html\">python3<\/a><\/p>\n<h3>Explanation of what you are doing wrong.<\/h3>\n<p>When you do the following sentence:<\/p>\n<pre><code>csv = open('inlog.csv', 'r').read().split('\\n')[1].split(';')\n<\/code><\/pre>\n<p>You are opening the file, read all the file then split the file by <code>\\n<\/code> character, with this you would obtain the following list <code>['user1;pass1';'user2;pass2','user3;pass3',...]<\/code> and the last step you do there, is select the second element with <code>[1]<\/code>, the result of this would be the string <code>'user2;pass2'<\/code>. But the statement does not finish here, there is another split that would give you the list <code>['user2','pass2']<\/code>.<\/p>\n<p>So you are comparing that the username is admin or is in the list <code>['user2','pass2']<\/code>. The same happens when you try to compare the password, but this time you select the third element.<\/p>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">1<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Find password by username <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] I am supposing your csv will be like this: user1, hash_pass_u1 user2, hash_pass_u2 user3, hash_pass_u3 &#8230; Just one note before the solution. You are importing the CSV module of Python and you did not use it in your code, such a silly import, just use it. The solution is simple import csv file=&#8221;yourcsv.csv&#8221; found &#8230; <a title=\"[Solved] Find password by username\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/\" aria-label=\"More on [Solved] Find password by username\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[483,349],"class_list":["post-26011","post","type-post","status-publish","format-standard","hentry","category-solved","tag-csv","tag-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Find password by username - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Find password by username - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] I am supposing your csv will be like this: user1, hash_pass_u1 user2, hash_pass_u2 user3, hash_pass_u3 ... Just one note before the solution. You are importing the CSV module of Python and you did not use it in your code, such a silly import, just use it. The solution is simple import csv file=&quot;yourcsv.csv&quot; found ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-14T18:56:33+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Find password by username\",\"datePublished\":\"2022-12-14T18:56:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/\"},\"wordCount\":216,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"csv\",\"python\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/\",\"name\":\"[Solved] Find password by username - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-12-14T18:56:33+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Find password by username\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Find password by username - JassWeb","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Find password by username - JassWeb","og_description":"[ad_1] I am supposing your csv will be like this: user1, hash_pass_u1 user2, hash_pass_u2 user3, hash_pass_u3 ... Just one note before the solution. You are importing the CSV module of Python and you did not use it in your code, such a silly import, just use it. The solution is simple import csv file=\"yourcsv.csv\" found ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/","og_site_name":"JassWeb","article_published_time":"2022-12-14T18:56:33+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Find password by username","datePublished":"2022-12-14T18:56:33+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/"},"wordCount":216,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["csv","python"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/","url":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/","name":"[Solved] Find password by username - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-12-14T18:56:33+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-find-password-by-username\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Find password by username"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1776403586","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/26011","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=26011"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/26011\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=26011"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=26011"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=26011"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}