Created get.py
This commit is contained in:
		
							
								
								
									
										31
									
								
								src/database/get.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										31
									
								
								src/database/get.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,31 @@
 | 
				
			|||||||
 | 
					import mariadb
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_master_pass(con: mariadb.Connection, id: int) -> tuple[bytes, bytes]:
 | 
				
			||||||
 | 
					    """Returns tuple of salt and hashed master password"""
 | 
				
			||||||
 | 
					    cursor = con.cursor()
 | 
				
			||||||
 | 
					    cursor.execute("SELECT salt, passwd FROM master_pass IF user_id = ?", [id])
 | 
				
			||||||
 | 
					    result = cursor.fetchone()
 | 
				
			||||||
 | 
					    cursor.close()
 | 
				
			||||||
 | 
					    return result
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_accounts(con: mariadb.Connection, id: int) -> list[str]:
 | 
				
			||||||
 | 
					    """Returns list of user accounts"""
 | 
				
			||||||
 | 
					    cursor = con.cursor()
 | 
				
			||||||
 | 
					    cursor.execute("SELECT acc_name FROM accounts IF user_id = ?", [id])
 | 
				
			||||||
 | 
					    return [i[0] for i in cursor.fetchall()]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_account_info(
 | 
				
			||||||
 | 
					    id: int, name: str, con: mariadb.Connection
 | 
				
			||||||
 | 
					) -> tuple[bytes, bytes, bytes]:
 | 
				
			||||||
 | 
					    """Returns tuple of salt, login and password"""
 | 
				
			||||||
 | 
					    cursor = con.cursor()
 | 
				
			||||||
 | 
					    cursor.execute(
 | 
				
			||||||
 | 
					        """SELECT salt, enc_login, enc_pass IF user_id = ? AND acc_name = ?""",
 | 
				
			||||||
 | 
					        [id, name],
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    result = cursor.fetchone()
 | 
				
			||||||
 | 
					    cursor.close()
 | 
				
			||||||
 | 
					    return result
 | 
				
			||||||
		Reference in New Issue
	
	Block a user