{"id":1313,"date":"2024-06-24T17:15:16","date_gmt":"2024-06-24T17:15:16","guid":{"rendered":"https:\/\/iotthinghub.com\/?p=1313"},"modified":"2024-08-11T15:22:21","modified_gmt":"2024-08-11T15:22:21","slug":"password-locker-using-eeprom","status":"publish","type":"post","link":"https:\/\/iotthinghub.com\/?p=1313","title":{"rendered":"Password locker using EEPROM"},"content":{"rendered":"\n<p class=\"has-text-color has-link-color wp-elements-1 wp-block-paragraph\" style=\"color:#5c5c5c\">For security reason sometime we need password locking controller. In This article we developed a password locker. Since password is nothing but a character of string. So we need to control string function carefully. Let\u2019s begin our journey with string handling.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"447\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/string-handaling-1024x447.jpg\" alt=\"\" class=\"wp-image-1315\" style=\"width:529px;height:auto\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/string-handaling-1024x447.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/string-handaling-300x131.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/string-handaling-768x335.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/string-handaling.jpg 1095w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"has-text-color has-link-color has-medium-font-size wp-elements-2 wp-block-paragraph\" style=\"color:#1a1a1a\"><strong>strcat() and strncat()<\/strong><\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-3 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The strcat() or strncat() function join two strings together.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-4 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcat(string1,string2);<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-5 wp-block-paragraph\" style=\"color:#5c5c5c\">Here all the characters of string2 are added to string1 by removing the null character at the end of string1.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-6 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strncat(string1,string2,n); here n is the number of characters<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-7 wp-block-paragraph\" style=\"color:#5c5c5c\">This statement will concatenate the left-most n characters of string2 and add to string1 by removing the null character at the end of string1.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-8 wp-block-paragraph\" style=\"color:#2f2f2f\"><strong>strncmp() and strncmp()<\/strong><\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-9 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;The strcmp() function compares two string indentified by the arguments and has a value 0 if they are equal. If they are not equal, it contents the numeric difference between the first no matching characters in the strings.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-10 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.e. int i;<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-11 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;i=strcmp(string1,string2);<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-12 wp-block-paragraph\" style=\"color:#5c5c5c\">Similarly, strncmp(string1,string2);&nbsp; compares the left most n characters of string1 to string2 and returns<\/p>\n\n\n\n<ol style=\"color:#5c5c5c;list-style-type:upper-roman\" class=\"wp-block-list has-text-color has-link-color wp-elements-13\">\n<li>0 if they are equal<\/li>\n\n\n\n<li>negative number, if string1 sub-string is less than string2 and<\/li>\n\n\n\n<li>positive number, otherwise<\/li>\n<\/ol>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-14 wp-block-paragraph\" style=\"color:#202020\"><strong>&nbsp;strcpy() and strncpy()<\/strong><\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-15 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strcpy(string1,string2);<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-16 wp-block-paragraph\" style=\"color:#5c5c5c\">This statement copies the characters of string2 to string1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strncpy(string1,string2);&nbsp;&nbsp;&nbsp; here n is the number of characters<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-17 wp-block-paragraph\" style=\"color:#5c5c5c\">This statement copies the first n characters of the source string2 into the target string1.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-18 wp-block-paragraph\" style=\"color:#2f2f2f\"><strong>strlen() function<\/strong><\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-19 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This function returns the number of characters in a string.<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-20 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; i.e. int n;<\/p>\n\n\n\n<p class=\"has-text-color has-link-color wp-elements-21 wp-block-paragraph\" style=\"color:#5c5c5c\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; n= strlen(string); Let make a password locker with 3&#215;4 matrix keypad display in which a predefined password is stored in the flash memory and as soon as the password match, a bit active. In this program we give 4 chances to put the right password. If the password is correct than PINC0 will be set to active some relay. If the password is incorrect in four chances then the processor will blocked and no effect on the key-button.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; auto-links: false; title: ; quick-code: false; notranslate\" title=\"\">\n#include&lt;avr\/eeprom.h&gt;\n#include&lt;avr\/io.h&gt;\n#include&lt;stdio.h&gt;\n#include&lt;string.h&gt;\n#include&lt;util\/delay.h&gt;\n#include&quot;keypad.h&quot;\n#include&quot;lcd.h&quot;\nunsigned char j,display&#x5B;20];\nchar StringData&#x5B;]=&quot;pass091109&quot;;\t\t\t\/*****This is your passward 091109***********\/\nchar im&#x5B;20]=&quot;pass&quot;;\nuint8_t sample,chance=4;\nint locker;\nint main(void)\n{\n\/********************************Store in EEPROM*****************************************\/\neeprom_update_block (( const void *) StringData , ( void *) 12, sizeof(StringData));\n\/****************************************************************************************\/\nkeypad_init();\nDDRC|=(1&lt;&lt;DDC0);\nLCD_INIT();\nDDRC&amp;=~(1&lt;&lt;DDC1);\t\t\t\t\t\t\t\t\t\t\t\t\/\/Enter key\nPORTC|=(1&lt;&lt;PC1);\nSTART:;\nLCD_Clear();\nLCD_write_string(1,1,&quot;Press any key&quot;);\n_delay_ms(1000);\nsample=PINC&amp;(1&lt;&lt;PC1); \t\t\t\t\t\t\t\t\t\t\/\/PulUp internal resistance\nwhile(sample)\n{\n\t\tsample=PINC&amp;(1&lt;&lt;PC1);\n\t\tj=key_press(0x7f);\n\t\tLCD_write_string(number,2,&quot;*&quot;);\n\t\tim&#x5B;number+3]=j;\n\t\tchance=chance-(!sample);\n\t\t\n\t}\n\/*Filter section*\/\n\/**************************************************************************************\/\nim&#x5B;3]=&#039;s&#039;;\nchar StringOfData &#x5B;sizeof(StringData)];\neeprom_read_block (( void *) StringOfData , ( const void *) 12, sizeof(StringData)) ;\n\/**************************************************************************************\/\nlocker=strcmp(StringOfData,im);\nif(locker)\n\t{\n\tPORTC&amp;=~(1&lt;&lt;PC0);\n\tLCD_write_string(1,1,&quot;Pass. incurrect&quot;);\n\tcleardata();\t\t\t\t\t\t\/\/clear storage\n\t_delay_ms(1000);\n\tsprintf(display,&quot;%d chance left       &quot;,chance);\n\tLCD_write_string(1,1,display);\n\t_delay_ms(1000);\n\tif(chance==0)\n\t\t{\n\t\t\t\tLCD_write_string(1,1,&quot;****************&quot;);\n\t\t\t\tLCD_write_string(1,2,&quot;*****locked*****&quot;);\n\t\t\t\tgoto END;\n\t\t}\n\tgoto START;\n\t}\n\telse\n\t\t{\n\t\t\t\tPORTC|=(1&lt;&lt;PC0);\n\t\t\t\tLCD_write_string(1,1,&quot;Passward currect&quot;);\n\t\t\t\tLCD_write_string(1,2,&quot;******open******&quot;);\n\t\t}\n\tEND:;\n\treturn 0;\n}\n<\/pre><\/div>\n\n\n<p class=\"has-text-color has-link-color has-upper-heading-font-size wp-elements-22 wp-block-paragraph\" style=\"color:#1a1a1a\">Here the default password is &#8212;&#8212;&nbsp; 091109&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"480\" src=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/password-locker-1024x480.jpg\" alt=\"\" class=\"wp-image-1324\" srcset=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/password-locker-1024x480.jpg 1024w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/password-locker-300x141.jpg 300w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/password-locker-768x360.jpg 768w, https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/06\/password-locker.jpg 1251w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-7387b849 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:33.33%\">\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Passward-Locker.rar\" style=\"padding-top:var(--wp--preset--spacing--20);padding-right:var(--wp--preset--spacing--40);padding-bottom:var(--wp--preset--spacing--20);padding-left:var(--wp--preset--spacing--40)\">download<\/a><\/div>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:66.66%\">\n<p class=\"has-text-color has-link-color wp-elements-23 wp-block-paragraph\" style=\"color:#1e1e1e\"><a href=\"https:\/\/iotthinghub.com\/wp-content\/uploads\/2024\/08\/Passward-Locker.rar\">Download the Hex file with proteus simulation<\/a><\/p>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>For security reason sometime we need password locking controller. In This article we developed a password locker. Since password is nothing but a character of string. So we need to control string function carefully. Let\u2019s begin our journey with string handling. strcat() and strncat() &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The strcat() or strncat() function join two strings together. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-1313","post","type-post","status-publish","format-standard","hentry","category-eeprom"],"_links":{"self":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1313"}],"version-history":[{"count":10,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1313\/revisions"}],"predecessor-version":[{"id":2563,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=\/wp\/v2\/posts\/1313\/revisions\/2563"}],"wp:attachment":[{"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/iotthinghub.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}