Getting back a permalink from custom url

No, there is no permalink. Because it’s a bespoke URL there’s nothing to latch on to. You’d need to generate such a function yourself from scratch.

Luckily, your URL is just the word login/ with an ID on the end, so when you need a URL, just write out login/ and put the ID on the end. Wrap it in a call to site_url to change it from a relative path to an absolute path.

For the non-pretty version, just take the 'index.php?function=login&id=$matches[1]' and swap $matches[1] for the ID you want.