1 /* crypt - simple encryption algorithm used for passwords 2 ** 3 ** Copyright 2001 Dr. Zoidberg Enterprises. All rights reserved. 4 */ 5 6 7 #include <Message.h> 8 9 #include <string.h> 10 #include <crypt.h> 11 12 13 static const char key[PASSWORD_LENGTH + 1] = "Dr. Zoidberg Enterprises, BeMail"; 14 15 16 _EXPORT char *get_passwd(const BMessage *msg,const char *name) 17 { 18 char *encryptedPassword; 19 ssize_t length; 20 if (msg->FindData(name,B_RAW_TYPE,(const void **)&encryptedPassword,&length) < B_OK || !encryptedPassword || length == 0) 21 return NULL; 22 23 char *buffer = new char[length]; 24 passwd_crypt(encryptedPassword,buffer,length); 25 26 return buffer; 27 } 28 29 30 _EXPORT bool set_passwd(BMessage *msg,const char *name,const char *password) 31 { 32 if (!password) 33 return false; 34 35 ssize_t length = strlen(password) + 1; 36 char *buffer = new char[length]; 37 passwd_crypt((char *)password,buffer,length); 38 39 msg->RemoveName(name); 40 status_t status = msg->AddData(name,B_RAW_TYPE,buffer,length,false); 41 42 delete [] buffer; 43 return (status >= B_OK); 44 } 45 46 47 _EXPORT void passwd_crypt(char *in,char *out,int length) 48 { 49 int i; 50 51 memcpy(out,in,length); 52 if (length > PASSWORD_LENGTH) 53 length = PASSWORD_LENGTH; 54 55 for (i = 0;i < length;i++) 56 out[i] ^= key[i]; 57 } 58 59