If someone is connected to the wifi but can’t remember the code to share with you (maybe they lost that little card with the details you need or perhaps the router with the password printed on it is hidden behind a pile of books etc) you can just run the commands below in Terminal (Mac) or Command Prompt (PC):
Mac:
security find-generic-password -wa YourWiFiNetworkNameHere
PC:
netsh wlan show profile name=YourWiFiNetworkNameHere key=clear