Python Forum
I need help using Python to generate usernames and passwords with excel documents - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: I need help using Python to generate usernames and passwords with excel documents (/thread-18125.html)



I need help using Python to generate usernames and passwords with excel documents - Jannejannesson - May-06-2019

Hey guys, I need some serious help and guidance with creating a script. I realize I'm well over my head here but I still feel somehow I'm on the verge of "making something great". Worth noting is I'm incredibly new to python modules.

So, what I want is a python script that takes the existing content out of 1 excel file (called names.xsl) and then creates a new excel file but with an additional 2 columns, Username & Password. Now I have a function that generates a random 8 letter password. But I also need a function that generates a username based upon their names and room number(Which anybody is welcome to come with suggestions how to solve).

Layout of names.xsl:
A , B ,C , D
Name, socialsecuritynr, room, tel
Amy Anderson, 12345678, 636, 070xxx
etc etc (there are 33 names)

Layout of names_mod.xsl:
A , B , C , D , E , F
Name, socialsecuritynr, room, tel, Username, Password
Amy Anderson, 12345678, 636, 070xxx, amy636, randpa55

  1 import pandas as pd                                                             
  2 from pandas import ExcelWriter                                                  
  3 from pandas import ExcelFile                                                    
  4 import numpy as np                                                              
  5 import xlsxwriter                                                               
  6                                                                                 
  7 import random                                                                   
  8 import string                                                                   
  9                                                                                 
 10 def randompassword(stringLength=6):                                             
 11     lettersAndDigits = string.ascii_letters + string.digits                     
 12     return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))
 13 print (randompassword(8))                                                       
 14                                                                                 
 15 df = pd.read_excel('names.xls', sheet_name='Sheet1')                            
 16                                                                                 
 17 workbook = xlsxwriter.Workbook('names_mod.xls')                                 
 18 worksheet = workbook.add_worksheet()                                            
 19                                                                                 
 20 worksheet.write('E1', 'Username')                                           
 21 worksheet.write('F1', 'Password')                                               
 22 worksheet.write('F2-34',(randompassword(8))                                     
 23 workbook.close()                                                                
 24                                                                                 
 25 df1 = pd.read_excel('names_mod.xls', sheet_name='Sheet1')                       
 26 print(df1)    
I realize this is A LOT to ask and the whole sript is a complete mess at the moment.. but any help is muchly appreciated, I've been at this for a good week now and could really use some help. Please let me know if I'm breaking any forum rules or need to clarify anything. Thanks in advance.


RE: I need help using Python to generate usernames and passwords with excel documents - Yoriz - May-06-2019

To get the username from
Output:
Amy Anderson, 12345678, 636, 070xxx
to
Output:
amy636
Use split on the name and pair it with room.


RE: I need help using Python to generate usernames and passwords with excel documents - Jannejannesson - May-06-2019

Any chance you could be more specific? I know how to use split, just not when there's an excel file involved.


How do I use my python functions to fill excel columns using openpyxl module? - Jannejannesson - May-08-2019

Hey guys, I'm incredibly new to Python and even more so to its modules.

I have an excel file (names.xsxl) with 33 names and info. I'm trying to create a script that generates a random username as well as a password for each user in the 'E' and 'F' column respectively. How would I do this with the help of my two functions?


I hope I'm making myself clear, if I'm not, don't hesitate to ask for a clarification. Here's my code so far:

  1 import random                                                                   
  2 import string                                                                                                                           
  8 from openpyxl import workbook                                                   
  9 from openpyxl import load_workbook                                              
 10 import xlrd                                                                     
 11                                                                                 
 12 wb = load_workbook('names.xlsx')  #reads the names.xlsx file                                              
 13 wb.save('names_mod.xlsx')         #saves it with the name: names_mod.xslx                                              
 14                                                                                 
 15 def randompassword(stringLength=8):   #creates a random password                                          
 16     lettersAndDigits = string.ascii_letters + string.digits                     
 17     return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))
 18                                                                                 
 19 def username(stringLength=5):         #creates a random username                                     
 20     lettersAndDigits = string.ascii_letters + string.digits                     
 21     return ''.join(random.choice(lettersAndDigits) for i in range(stringLength))
Thankful for any help.