0

Here's the following code:

import pyodbc
import pandas as pd
from pandas import ExcelWriter
import sys
import time
import getpass

username = input('Please enter username starting with COMPANY\\: ')
password = getpass.getpass('Please enter your password: ')


cnxn = pyodbc.connect(
    'Driver={ODBC DRiver 17 for SQL Server};'
    'Server=COMPANY;'
    'Database=COMPANY;'
    'uid=' + username + ';pwd=' + password + ';Trusted_connection=yes')

df = pd.read_sql_query(
    'doesnt matter, hiding for business',
    cnxn)

df['Counts'] = df.groupby(['DocumentNo'])['ItemNo'].transform('count')

df2 = df[df['Counts'] == 1]

df3 = df2[['ItemNo','DocumentNo','QO']].copy()

df3['Counts'] = df3.groupby(['ItemNo'])['DocumentNo'].transform('count')

df3 = df3[df3['Counts'] > 1]

df4 = df3.groupby(['ItemNo']).QO.sum().reset_index()

df5 = df3.merge(df4, on='ItemNo', how='left')

df6 = df5.groupby(['ItemNo','QO_y'])['DocumentNo'].apply(lambda x: ' | '.join(x.astype(str))).reset_index()


location = input('Please put the exact folder location where you want to put the excel file, and name of file: ')

writer = ExcelWriter(location)
df6.to_excel(writer,'Data')
writer.save()

time.sleep(10)
sys.exit()

After using pyinstaller to create one file, I open the program up. I enter the username, no problem. I can enter any password I want and it will then prompt for the excel file location. The file is correct when it comes in. Why is this the case? These password are user specific, so it shouldn't be the case that I can enter whatever I want. Secondarily, when another user tries to open the program on shared server, they place their password in and the program closes.

Please note that I hid company related info including the SQL query. It doesn't need to be pointed out to me.

Axe319
  • 4,255
  • 3
  • 15
  • 31
bohzwah
  • 77
  • 7
  • 1
    Doesn't `Trusted_connection=yes` use Windows credentials and render `uid` and `pwd` useless? – Axe319 Sep 29 '20 at 16:21
  • 1
    This might be helpful https://stackoverflow.com/a/21518284/12479639 – Axe319 Sep 29 '20 at 16:31
  • Yeah this works! But any particular reason why when I put in Company\billybob, it enters it as Company\\billybob? Is there a way for it to go straight through with only 1 \? – bohzwah Sep 29 '20 at 16:39
  • In python `\\` is an escape character. For a better explanation than I can give, see this https://stackoverflow.com/questions/24085680/why-do-backslashes-appear-twice – Axe319 Sep 29 '20 at 16:50

0 Answers0