+
+int csa_checkpasswordquality(char *password) {
+ int i, cntweak = 0, cntdigits = 0, cntletters = 0;
+ if (strlen(password) < 6)
+ return QM_PWTOSHORT;
+
+ if (strlen(password) > 10)
+ return QM_PWTOLONG;
+
+ for ( i = 0; password[i] && i < PASSLEN; i++ ) {
+ if ( password[i] == password[i+1] || password[i] + 1 == password[i+1] || password[i] - 1 == password[i+1] )
+ cntweak++;
+ if(isdigit(password[i]))
+ cntdigits++;
+ if(islower(password[i]) || isupper(password[i]))
+ cntletters++;
+ if(password[i] < 32 || password[i] > 127)
+ return QM_PWINVALID;
+ }
+
+ if( cntweak > 3 || !cntdigits || !cntletters)
+ return QM_PWTOWEAK;
+
+ return -1;
+}
+
+reguser *csa_createaccount(char *username, char *password, char *email) {
+ time_t t = time(NULL);
+ char *local, *dupemail;
+
+ dupemail = strdup(email);
+ local=strchr(dupemail, '@');
+ if(!local) {
+ free(dupemail);
+ return NULL;
+ }
+ *(local++)='\0';
+
+ reguser *rup=getreguser();
+ rup->status=0;
+ rup->ID=++lastuserID;
+ strncpy(rup->username,username,NICKLEN); rup->username[NICKLEN]='\0';
+ rup->created=t;
+ rup->lastauth=0;
+ rup->lastemailchange=t;
+ rup->lastpasschange=t;
+ rup->flags=QUFLAG_NOTICE;
+ rup->languageid=0;
+ rup->suspendby=0;
+ rup->suspendexp=0;
+ rup->suspendtime=0;
+ rup->lockuntil=0;
+ strncpy(rup->password,password,PASSLEN); rup->password[PASSLEN]='\0';
+ rup->email=getsstring(email,EMAILLEN);
+ rup->lastemail=NULL;
+
+ rup->localpart=getsstring(dupemail,EMAILLEN);
+ free(dupemail);
+
+ rup->domain=findorcreatemaildomain(email);
+ addregusertomaildomain(rup, rup->domain);
+ rup->info=NULL;
+ rup->lastuserhost=NULL;
+ rup->suspendreason=NULL;
+ rup->comment=NULL;
+ rup->knownon=NULL;
+ rup->checkshd=NULL;
+ rup->stealcount=0;
+ rup->fakeuser=NULL;
+ addregusertohash(rup);
+
+ return rup;
+}