Update lib.php

add credentials check